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>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};
void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = x+dx[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] == 1) continue;

      if(mp[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++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#define fi first
#define se second
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=10000009;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int c[20][20];
long long int dp[20][20];
int main() {
	int X,Y;
	while(true){
		long long int ans=0;
		cin>>X>>Y;
		if(X+Y==0) break;
		for(int i=1;i<=Y;i++){
			for(int j=1;j<=X;j++){
				cin>>c[i][j];
			}
		}
		for(int i=1;i<=X;i++){
			if(c[1][i]==1){
				dp[1][i]=0;
			}
			if(c[1][i]==0){
				dp[1][i]=1;
			}
			if(c[1][i]==2){
				dp[1][i]=1;
				dp[3][i]=1;
			}
		}
		for(int i=2;i<=Y;i++){
			for(int j=1;j<=X;j++){
				if(c[i][j]==1) dp[i][j]=0;
				else if(c[i][j]==0){
					for(int k=0;k<3;k++){
						if(c[i-1][j-1+k]!=2){
							dp[i][j]+=dp[i-1][j-1+k];
						}
					}
				}
				else{
					if(c[i-1][j]!=2){
						dp[i][j]+=dp[i-1][j];
						dp[i+2][j]+=dp[i][j];
					}
					else{
						dp[i][j]=0;
					}
				}
			}
		}
		for(int i=Y;i<=Y+2;i++){
			for(int j=1;j<=X;j++){
				ans+=dp[i][j];
			}
		}
		for(int i=1;i<=Y+2;i++){
			for(int j=1;j<=X;j++){
				dp[i][j]=0;
			}
		}
		cout<<ans<<endl;
	}
}

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

int DP[18][17];
int field[17][17];
int x,y;

int main(){
	while(true){
		cin >> x >> y;
		if(!x && !y)
			return 0;
		
		for(int i=1; i<=y; i++)
			for(int k=1; k<=x; k++)
				cin >> field[i][k];
		for(int i=1; i<=x; i++)
			field[y+1][i] = 0;
		
		for(int i=1; i<=y+2; i++)
			for(int k=0; k<=x+1; k++){
				DP[i][k]=0;
				if(i==1 && k>0 && k<=x)
					if(field[i][k] == 0)
						DP[i][k] = 1;
			}
		
		for(int i=2; i<=y; i++){
			for(int k=1; k<=x; k++){
				if(field[i][k] == 0)
					DP[i][k] += DP[i-1][k-1] + DP[i-1][k] + DP[i-1][k+1];
				else if(field[i][k] == 2){
					int n = i+2;
					while(true){
						if(field[n][k] == 0){
							DP[n][k] += DP[i-1][k];
							break;
						}else if(field[n][k] == 1)
							break;
						else
							n+=2;
					}
				}
			}
		}
		
		int ans=0;
		for(int i=y; i<=y+2; i++)
			for(int k=1; k<=x; k++)
				ans += DP[i][k];
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
 
int main(){
        int x,y;
        while(cin>>x>>y,x){
                int D[16][16],P[16][16],ans=0;
                for(int i=0;i<256;i++)P[i/16][i%16]=0;
                for(int i=0;i<y;i++)for(int j=0;j<x;j++)cin>>D[i][j];
                for(int i=0;i<x;i++)if(!D[0][i])P[0][i]=1;
                for(int i=0;i<y-1;i++){
                        for(int j=0;j<x;j++){
                                if(!D[i][j]){
                                        if (D[i + 1][j] != 1) P[i+1][j]+=P[i][j];
                                        if(j>0 && !D[i + 1][j - 1])P[i+1][j-1]+=P[i][j];
                                        if(j<x-1 && !D[i + 1][j + 1])P[i+1][j+1]+=P[i][j];
                                }
                                if(D[i][j]==2){
                                        if(i+2>y-1)P[i+1][j]+=P[i][j];
                                        else P[i+2][j]+=P[i][j];
                                }
                        }
                }
                for(int i=0;i<x;i++)ans+=P[y-1][i];
                cout<<ans<<endl;
        }
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

const int moveTo[][2] = {{-1,1},{0,1},{1,1}};

int stage[17][17];
int dp[17][17];

int main(){
	int w,h;
	while(~scanf("%d %d",&w,&h)){
		if(w==h && h==0) break;
		memset(stage,-1,sizeof(stage));
		memset(dp,0,sizeof(dp));
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				scanf("%d",&stage[y][x]);
			}
		}

		//space:0 tree:1 jump:2
		for(int x=0;x<w;x++){
			if(stage[0][x]!=1) dp[0][x] = 1;
		}

		for(int dy=1;dy<=h;dy++){
			for(int dx=0;dx<w;dx++){
				if(stage[dy][dx] != 1){			
					for(int j=0;j<3;j++){
						int sx = dx - moveTo[j][0];
						int sy = dy - moveTo[j][1];
						if(sx < 0 || sx >= w || sy < 0 || sy >= h-1) continue;

						//space:0 tree:1 jump:2
						if(stage[sy][sx]!=0) continue;
						if(stage[dy][dx]==2 && dx != sx) continue;

						dp[dy][dx] += dp[sy][sx];
					}

					int sx = dx;
					int sy = dy-2;
					if(sx >=0 && sx < w && sy >= 0 && sy < h-1){
						//space:0 tree:1 jump:2
						if(stage[sy][sx] == 2){
							dp[dy][dx] += dp[sy][sx];
						}
					}
				}
			}
		}

		int res=0;
		for(int y=h-1;y<=h;y++){
			for(int x=0;x<w;x++){
				res += dp[y][x];
			}
		}

		printf("%d\n",res);
	}

}