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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int x, y;
int field[16][16];
int dp[16][16];

int main(){
	while (cin >> x >> y&&x + y){
		REP(i, 16){
			REP(j, 16){
				dp[i][j] = 0;
				field[i][j] = 0;
			}
		}
		REP(i, y)REP(j, x)cin >> field[i][j];
		REP(j, x){
			if (field[0][j] == 0)dp[0][j] = 1;
		}
		REP(i, y - 1){
			REP(j, x){
				if (field[i][j] == 0){
					if (field[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j - 1 >= 0 && field[i + 1][j - 1] == 0){
						dp[i + 1][j - 1] += dp[i][j];
					}
					if (j + 1 < x&&field[i + 1][j + 1] == 0){
						dp[i + 1][j + 1] += dp[i][j];
					}
				}
				else if (field[i][j] == 2){
					if (i + 2 <= y - 1 && dp[i + 2][j] != 1){
						dp[i + 2][j] += dp[i][j];
					}
					else{
						dp[i + 1][j] += dp[i][j];
					}
				}
			}
		}
		//cout << endl;
		//REP(i, y){
		//	REP(j, x){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		int ans = 0;
		REP(j, x)ans += dp[y - 1][j];
		cout << ans << endl;
	}
}

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

int x, y, f[15][15];
long dp[15][15]; //座標

long rec(int a, int b){
	if(dp[a][b]>=0) return dp[a][b];

	long ret=0;
	//printf(" %d %d\n", a, b);
	
	if(b>=y-1) ret=1;
	else if(f[b][a]==0){
		for(int i=-1; i<=1; ++i){
			int na=a+i;
			if(na<0 || x<=na) continue;
			
			if(i==0){
				if(f[b+1][na]==1) ret+=0;
				else ret+=rec(na, b+1);
			}
			else{
				if(f[b+1][na]==0) ret+=rec(na, b+1);
				else ret+=0;	
			}
			
		}
	}
	else if(f[b][a]==1) ret=0;	
	else if(f[b][a]==2) ret+=rec(a, b+2);

	//printf(" %d %d ret=%ld\n", a, b, ret);
	return dp[a][b]=ret;	
}

int main(){
	while(1){
		scanf(" %d %d", &x, &y);
		if(x==0) break;	
		for(int i=0; i<y; ++i)
		for(int j=0; j<x; ++j)
		scanf(" %d", &f[i][j]);		
	
		memset(dp, -1, sizeof(dp));
		long ans=0;
		for(int i=0; i<x; ++i){
			if(f[0][i]==0) ans+=rec(i, 0);
			//printf(" ans=%ld\n", ans);	
		}
		
		printf("%ld\n", ans);
	}
}

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

int main(){
  int x,y;
  int grid[16][15];
  int c[16][15];
  int dx[] = {-1,0,1};

  for(;;){
    cin >> x >> y;
    if(!x && !y)break;

    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++)cin >> grid[i][j];
    for(int j=0;j<x;j++)grid[y][j] = 0;

    for(int i=0;i<y+1;i++)
      for(int j=0;j<x;j++)c[i][j] = 0;

    for(int i=0;i<x;i++)
      if(!grid[0][i])c[0][i] = 1;

    for(int i=0;i<y-1;i++){
      for(int j=0;j<x;j++){
	if(!grid[i][j]){
	  for(int k=0;k<3;k++){
	    int sx = j+dx[k];
	    if(sx<0 || x<=sx)continue;
	    if(!grid[i+1][sx] || (grid[i+1][sx]==2 && k==1))c[i+1][sx] += c[i][j];
	  }
	}
	if(grid[i][j] == 2){
	  if(grid[i+2][j]!=1)c[i+2][j] += c[i][j];
	}
      }
    }

    int ans = 0;
    for(int i=0;i<x;i++){
      ans += c[y-1][i];
      ans += c[y][i];
    }
    /*
    for(int i=0;i<y+2;i++){
      for(int j=0;j<x;j++)cout << c[i][j] << " ";
      cout << endl;
    }
    */
    cout << ans << endl;
  }
}

C++: #include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
void saiki(int x,int y){
  if(y >= h-1) memo[y][x]++;
  else 
    for(int i=-1;i<=1;i++) {
      int nx = x+i, ny = y+1;
      if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;
      if(nx <0|| nx >= w ||mp[ny][nx] != 0) continue;
      if(memo[ny][nx]==0) saiki(nx,ny);
      memo[y][x] += memo[ny][nx];
    }
  if(memo[y][x] == 0) mp[y][x] = 1;
}
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
     
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
  
    for(int i=0;i<w;i++)
      if(mp[0][i] !=1) saiki(i,0);
     
    int cnt = 0;
    for(int i=0;i<w;i++)cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  while(1){
    int w,h,mp[20][20]={},dp[20][20] ={};
    cin >> w >> h;
    if(w==0 && h==0) break;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) cin >> mp[i][j];

    for(int i=0;i<w;i++) if(mp[0][i]==0) dp[0][i] = 1;

    int ans=0;    
    for(int i=0;i<h-1;i++)
      for(int j=0;j<w;j++) 
	for(int k=-1;k<=1;k++){
	  int nx=j+k,ny=i+1;
	  if(nx<0||nx>=w || mp[i][j] !=0) continue;
	  if(k==0)while(mp[ny][nx]==2) ny+=2;
	  if(mp[ny][nx]!=0) continue;
	  dp[ny][nx]+= dp[i][j];
	  if(ny >= h-1) ans+=dp[i][j];
	}
    cout << ans <<endl;
  }
  return 0;
}