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<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
int X,Y,imap[20][20];
const int dx[3] = {-1,0,1};
const int dy[3] = {1,1,1};
int sam,dp[20][20];

int solve(){
  
  int ans = 0;
  for(int i=0;i<=Y;i++)for(int j=0;j<=X;j++)dp[i][j] = (i==0 && imap[i][j] != 1)?1:0; 

  for(int i=0;i<Y-1;i++){
    for(int j=0;j<X;j++){
      if(dp[i][j] == 0 || imap[i][j] == 1)continue;
      if(imap[i][j] == 0){
	for(int k=0;k<3;k++){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(0<= nx && nx<X && 0<= ny && ny < Y && imap[ny][nx] != 1){
	      if((k == 0 || k == 2) && imap[ny][nx] == 2)continue;
	      dp[ny][nx]+=dp[i][j];
	  }
	}
      }
      else if(imap[i][j] == 2){
	if(i+2 < Y && imap[i+2][j] != 1){
	  dp[i+2][j]+=dp[i][j];
	}
	else if(i+2 >= Y){
	  //if(imap[Y-1][j] != 1)
	    dp[Y-1][j]+=dp[i][j];
	}
      }
    }
  }
  /*
  cout << endl;
    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++)cout << dp[i][j] << " ";
	cout << endl;
    }
  */
    for(int i=0;i<X;i++)ans += dp[Y-1][i];
    return ans;
}



bool Init(){
  cin >> X >> Y;
  if(X+Y == 0)return false;
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++){
      cin >> imap[i][j];
    }
  }
  sam = 0;
  return true;
}



int main(){
  while(true){
    if(!Init())break;
    cout << solve() << endl;
  }
  return 0;
}

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

int w,h;
int map[16][16];
int dp[16][16][4][2];

int rec(int x,int y,int state,bool str){
    if(state == 1 || x < 0 || x >= w) return 0;
    if(state == 2 && !str) return 0;
    if(y >= h-1) return 1;
    if(dp[y][x][state][str] != -1) return dp[y][x][state][str];
    int res;
    if(state == 2) res = rec(x,y+2,map[y+2][x],true);
    else res = (rec(x-1,y+1,map[y+1][x-1],false) + rec(x,y+1,map[y+1][x],true) + rec(x+1,y+1,map[y+1][x+1],false));
    return dp[y][x][state][str] = res;
}

int main(){
    while(cin >> w >> h,w||h){
        memset(dp,-1,sizeof(dp));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) cin >> map[i][j];
        }
        int d = 0;
        for(int i=0;i<w;i++) d += rec(i,0,map[0][i],true);
        cout << d << endl;
    }
}

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

int main(){
	while(1){
		int X, Y, c;
		vector<vector<int> > grid, count;
	
		cin>>X>>Y;
		if((X == 0) && (Y == 0))
			break;

		grid.resize(X+2);
		for(int i=0;i<X+2;i++)
			grid[i].resize(Y+2);

		for(int j=0;j<Y+2;j++){
			for(int i=0;i<X+2;i++){
				if((i == 0) || (i == X+1) || (j == 0) || (j == Y+1)){
					grid[i][j] = 1;
				}else{
					cin>>c;
					grid[i][j] = c;
				}
			}
		}

		count.resize(X+2);
		for(int i=0;i<X+2;i++)
			count[i].resize(Y+2);

		for(int i=0;i<X+2;i++)
			for(int j=0;j<Y+2;j++)
				count[i][j] = 0;

		for(int i=1;i<=X;i++)
			if(grid[i][1] == 0)
				count[i][1]++;

		for(int j=2;j<=Y;j++){
			for(int i=1;i<=X;i++){
				if(grid[i][j] == 1){
					continue;
				}else if(grid[i][j] == 2){
					count[i][j] += count[i][j-1];
					if(grid[i][j-2] == 2)
						count[i][j] += count[i][j-2];
				}else{
					for(int k=-1;k<=1;k++)
						if(grid[i+k][j-1] != 2)
							count[i][j] += count[i+k][j-1];
					if(grid[i][j-2] == 2)
						count[i][j] += count[i][j-2];
				}
			}
		}

		int ans = 0;
		for(int i=1;i<=X;i++){
			ans += count[i][Y];
			if(grid[i][Y-1] == 2)
				ans += count[i][Y-1];
		}
		
		cout<<ans<<endl;
	}
	return 0;
}

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

int dfs(int x,int y);
int mas[20][20];
int X,Y;

int main(){
	while(1){
		cin >> X >> Y;
		if(X == 0 && Y == 0) break;
		for(int i=0;i<Y;i++){
			for(int j=0;j<X;j++){
				cin >> mas[i][j];
			}
		}
		int ans = 0;
		for(int i=0;i<X;i++){
			if(mas[0][i] == 0){
				ans += dfs(i,0);
			}
		}
		cout << ans << endl;
	}
}

int dfs(int x,int y){
	int cou = 0;
	if(y>=Y-1) return 1;
	for(int i=-1;i<2;i++){
		int nx = x + i;
		int ny = y + 1;
		if(nx >= 0 && nx < X){
			if(i == 0 && mas[ny][nx] == 2){
				while(mas[ny][nx] == 2){
					ny += 2;
				}
				cou += dfs(nx,ny);
			}
			else if(mas[ny][nx] == 0){
				cou += dfs(nx,ny);
			}
		}
	}
	return cou;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define MAX 16

int main()
{
    int H, W;
    while (cin >> W >> H, W) {
        vector<vector<int>> a(H, vector<int>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> a[i][j];
            }
        }
        int dp[MAX][MAX] = {{}};
        for (int i = 0; i < W; i++) {
            dp[0][i] = (a[0][i] == 0);
        }

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (dp[i][j] == 0 || a[i][j] == 1) continue;
                if (a[i][j] == 2) {
                    int ni = min(i + 2, H);
                    if (ni < H && a[ni][j] == 1) continue;
                    dp[ni][j] += dp[i][j];
                } else {
                    if (i + 1 == H) continue;
                    for (int k = -1; k <= 1; k++) {
                        int ni = i + 1;
                        int nj = j + k;
                        if (nj < 0 || nj >= W) continue;
                        if (a[ni][nj] == 1) continue;
                        if (a[ni][nj] == 2 && j != nj) continue;
                        dp[ni][nj] += dp[i][j];
                    }
                }
            }
        }
        int res = 0;
        for (int i = 0; i < W; i++) {
            res += dp[H-1][i] + dp[H][i];
        }
        cout << res << endl;
    }
    return 0;
}