Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		X, _ := strconv.Atoi(buf[0])
		Y, _ := strconv.Atoi(buf[1])
		if X == 0 && Y == 0 {
			break
		}
		tbl := make([][]int, Y+2)
		field := make([][]int, Y+2)
		for i := range field {
			field[i] = make([]int, X+2)
			tbl[i] = make([]int, X+2)
			for j := range field[i] {
				field[i][j] = 2
				tbl[i][j] = 0
			}
		}
		buf_ := make([][]string, Y)
		for i := range buf_ {
			scanner.Scan()
			buf_[i] = strings.Split(scanner.Text(), " ")
		}
		for i := 1; i <= Y; i++ {
			for j := 1; j <= X; j++ {
				field[i][j], _ = strconv.Atoi(buf_[i-1][j-1])
				switch field[i][j] {
				case 0:
					if i == 1 {
						tbl[i][j] = 1 // スタートy=1
					} else {
						if field[i-1][j-1] != 2 {
							tbl[i][j] += tbl[i-1][j-1] // 左上からやってくる
						}
						if field[i-1][j] != 2 {
							tbl[i][j] += tbl[i-1][j] // 真上からやってくる
						}
						if field[i-1][j+1] != 2 {
							tbl[i][j] += tbl[i-1][j+1] // 右上からやってくる
						}
						if field[i-2][j] == 2 {
							tbl[i][j] += tbl[i-2][j] // ジャンプしてくる
						}
					}
				case 1:
					tbl[i][j] = 0 // 障害物あり
				case 2:
					if field[i-1][j] != 2 {
						tbl[i][j] += tbl[i-1][j] // 真上からくる
					}
					if field[i-2][j] == 2 {
						tbl[i][j] += tbl[i-2][j] // ジャンプ台からジャンプしてくる
					}
				}
			}
		}
		sum := 0
		for i := 1; i <= X; i++ {
			sum += tbl[Y][i] // とびこさないでゴール
			if field[Y-1][i] == 2 {
				sum += tbl[Y-1][i] // 飛び越してゴール
			}
		}
		fmt.Println(sum)
	}
}

C++: #include <cstdio>
using namespace std;

int X, Y, c[15][15], dp[15][15];

int main(){
	while (scanf("%d%d", &X, &Y), X != 0) {
		for (int i = 0; i < Y; i++) {
			for (int j = 0; j < X; j++) {
				scanf("%d", &c[i][j]);
				dp[i][j] = 0;
			}
		}
		for (int i = 0; i < Y; i++) {
			for (int j = 0; j < X; j++) {
				if (i == 0 && c[i][j] != 1) {
					dp[i][j] = 1;
				}
				else {
					if (c[i][j] == 1) {
						if (i > 0 && c[i - 1][j] == 2) {
							dp[i][j] = dp[i - 1][j];
						}
						else {
							dp[i][j] = 0;
						}
					}
					else if (c[i][j] == 2) {
						dp[i][j] = dp[i - 1][j];
					}
					else {
						dp[i][j] = dp[i - 1][j];
						if (j > 0 && c[i-1][j-1] == 0) {
							dp[i][j] += dp[i - 1][j - 1];
						}
						if (j < X - 1 && c[i-1][j+1] == 0) {
							dp[i][j] += dp[i - 1][j + 1];
						}
					}
				}
			}
		}
		int sum = 0;
		for (int i = 0; i < X; i++) {
			sum += dp[Y - 1][i];
		}
		printf("%d\n", sum);
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>m>>n,n||m){
    int in[15][15]={0};
    int out[15][15]={0};
    rep(i,m){
      cin>>in[0][i];
      if(in[0][i]==0)out[0][i]=1;
    }
    loop(i,1,n){
      rep(j,m){
	cin>>in[i][j];
	if(in[i][j]==0){
	  if(j-1>=0&&in[i-1][j-1]!=2)out[i][j]+=out[i-1][j-1];
	  if(in[i-1][j]!=2)out[i][j]+=out[i-1][j];
	  if(j+1<m&&in[i-1][j+1]!=2)out[i][j]+=out[i-1][j+1];
	  if(i-2>=0&&in[i-2][j]==2)out[i][j]+=out[i-2][j];
	}else if(in[i][j]==2){
	  out[i][j]+=out[i-1][j];
	  if(i-2>=0&&in[i-2][j]==2)out[i][j]+=out[i-2][j];
	}
      }
    }
    int ans=0;
    rep(i,m){
      ans+=out[n-1][i];
      if(in[n-2][i]==2)ans+=out[n-2][i];
    }
    cout<<ans<<endl;
    //cout<<endl;
    //rep(i,n){rep(j,m)cout<<" "<<out[i][j];cout<<endl;}
    //cout<<endl;
  }
}

C++: // AOJ 0203
#include<iostream>
#include<cstring>

int X, Y;
int field[17][15];
int dp[15][15];

int main()
{
	while( std::cin >> X >> Y, X | Y )
	{
		memset( field, 0, sizeof( field ) );
		memset( dp, 0, sizeof( dp ) );

		for( int i = 0; i != Y; ++i )
			for( int j = 0; j != X; ++j )
				std::cin >> field[i][j];

		for( int i = 0; i != X; ++i )
			dp[0][i] = field[0][i] != 1;
		
		int ans = 0;
		for( int i = 1; i <= Y + 1; ++i )
		{
			for( int j = 0; j != X; ++j )
			{
				if( i < Y && field[i][j] != 1 )
				{
					for( int k = -1; k <= 1; ++k )
					{
						if( field[i][j] == 2 && k != 0 )
							continue;
						
						if( j + k >= 0 && j + k < X && !field[i-1][j+k] )
							dp[i][j] += dp[i-1][j+k];
					}
				}

				if( i - 2 > 0 && field[i-2][j] == 2 )
					dp[i][j] += dp[i-2][j];
			
				if( i >= Y - 1 )
					ans += dp[i][j];
			}
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
#include<map>
#include<string>
using namespace std;

int X, Y, Fld[17][15], memo[14][15];

int DFS(int y, int x){
	if(Fld[y][x] == 1) return 0;
	if(y >= Y-1) return 1;
	if(Fld[y][x] == 2) return DFS(y+2, x);
	if(memo[y][x] != -1) return memo[y][x];
	memo[y][x] = 0;

	for(int i = -1; i <= 1; i++){
		int ny = y+1, nx = x + i;
		if( nx < 0 || X <= nx || Fld[ny][nx] == 1 || (Fld[ny][nx] == 2 && i != 0) )
			continue;
		memo[y][x] += DFS(ny, nx);
	}

	return memo[y][x];
}

int main(){
	while(cin >> X >> Y, X || Y){
		fill_n( (int*)Fld, 17*15, 0 );
		for(int i = 0; i < Y; i++){
			for(int j = 0; j < X; j++){
				cin >> Fld[i][j];
			}
		}

		int ans = 0;
		fill_n( (int*)memo, 14*15, -1 );
		for(int i = 0; i < X; i++) if(Fld[0][i] == 0) ans += DFS(0, i);
		printf("%d\n", ans);
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

typedef pair<long long int, long long int> P;

int main(){
	
	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0){
			break;
		}
		int F[20][20];
		for(int i = 0; i < H; i++){
			for(int j = 1; j <= W; j++){
				cin >> F[i][j];
			}
		}
		long long int DP[20][20] = {};
		for(int i = 1; i <= W; i++){
			DP[0][i] = 1;
		}
		for(int i = 0; i < H - 1; i++){
			for(int j = 1; j <= W; j++){
				if(F[i][j] == 0){
					if(F[i + 1][j - 1] == 0){
						DP[i + 1][j - 1] += DP[i][j];
					}
					if(F[i + 1][j + 1] == 0){
						DP[i + 1][j + 1] += DP[i][j];
					}
					DP[i + 1][j] += DP[i][j];
				}else if(F[i][j] == 2){
					DP[i + 2][j] += DP[i][j];
				}
			}
		}
		long long int ans = 0;
		for(int i = 1; i <= W; i++){
			if(F[H - 1][i] != 1){
				ans += DP[H - 1][i];
			}
			ans += DP[H][i];
		}
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main() {
	int x, y;
	while (cin >> x >> y, x * y) {//
		int skimap[15][15] = {};//x = j y = i
		int dp[15][15] = {};//x = j y = i
		int flyover = 0;
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				cin >> skimap[i][j];
			}
		}
		for(int i = 0; i < x;i++){
			if (skimap[0][i] == 0)dp[0][i] = 1;
		}
		for (int i = 0; i < y - 1; i++) {
			for (int j = 0; j < x; j++) {
				if (skimap[i][j] == 0) {
					if (j - 1 >= 0) {
						if (skimap[i + 1][j - 1] == 0) {
							dp[i + 1][j - 1] += dp[i][j];
						}
					}
					if (skimap[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j + 1 < x) {
						if (skimap[i + 1][j + 1] == 0) {
							dp[i + 1][j + 1] += dp[i][j];
						}
					}
				}
				else if (skimap[i][j] == 1) {
					continue;
				}else {
					if (i + 2 < y) {
						dp[i + 2][j] = dp[i][j];
					}else {
						flyover += dp[i][j];
					}
				}
			}
		}
		int sum = flyover;
		for (int i = 0; i < x; i++) {
			sum += dp[y - 1][i];
		}
		cout << sum << endl;
	}
	return 0;
}