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>

#define MAX_N 15

using namespace std;

int map[MAX_N+1][MAX_N+1];
int dp[MAX_N+2][MAX_N+2];
int X, Y;
int ans;

void solve();

int main()
{
	while (cin>>X>>Y, X != 0 && Y != 0) {
		for (int i = 1; i <= Y; i++) {
			for (int j = 1; j <= X; j++) {
				cin>>map[j][i];
				dp[j][i] = 0;
			}
		}
		solve();
	}
	
}

void solve()
{
	for (int i = 1; i <= Y ; i++) {
		for (int  j = 1; j <= X; j++) {
			if (i == 1) {
				map[j][i] == 1 ? dp[j][i] = 0 : dp[j][i] = 1;
			} else {
				switch (map[j][i]) {
					case 0:
						if (map[j-1][i-1] != 2) {
							dp[j][i] += dp[j-1][i-1];
						}
						if (map[j][i-1] != 2) {
							dp[j][i] += dp[j][i-1];
						}
						if (map[j+1][i-1] != 2) {
							dp[j][i] += dp[j+1][i-1];
						}
						if (map[j][i-2] == 2) {
							dp[j][i] += dp[j][i-2];
						}
						break;
						
					case 1:
						dp[j][i] = 0;
						break;
						
					case 2:
						if (map[j][i-1] != 2) {
							dp[j][i] += dp[j][i-1];
						}
						if (map[j][i-2] == 2) {
							dp[j][i] += dp[j][i-2];
						}
						break;
						
					default:
						break;
				}
			}
			
		}
	}
	int ans = 0;
	for (int i = 1; i <= X; i++) {
		ans += dp[i][Y];
		if (map[i][Y-1] == 2) ans += dp[i][Y-1];
	}
	cout<<ans<<endl;
}

C++: #include <iostream>
#define N 15
using namespace std;
void func(int,int);
int jump(int,int);
int X,Y,data[N][N],memo[N][N];
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 >> data[i][j],memo[i][j]=0;
    for(int i=0;i<X;i++)
      if(data[0][i]==0) func(0,i);
    int cnt=0;
    for(int i=0;i<X;i++) cnt+=memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y==Y-1){
    memo[Y-1][x]=1;
    return ;
  }
  if(0<=x-1&&data[y+1][x-1]==0){
    if(memo[y+1][x-1]==0) func(y+1,x-1);
    memo[y][x]+=memo[y+1][x-1];
  }
  if(x+1<X&&data[y+1][x+1]==0){
    if(memo[y+1][x+1]==0) func(y+1,x+1);
    memo[y][x]+=memo[y+1][x+1];
  }
  if(data[y+1][x]==0){
    if(memo[y+1][x]==0) func(y+1,x);
    memo[y][x]+=memo[y+1][x];
  }
  if(data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r==-2) memo[y][x]+=1;
    else if(r!=-1){
      if(memo[r][x]==0) func(r,x);
      memo[y][x]+=memo[r][x];
    }
  }
  if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  while(1){
    y+=2;
    if(y>Y-1) return -2;
    if(data[y][x]==1) break;
    if(y==Y-1) return -2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

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

using namespace std;

int main(void)
{
	int x, y;
	while (cin >> x >> y, x || y){
		int field[20][20];
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		int dp[20][20] = {{0}};
		for (int j = 1; j <= x; j++){
			if (field[1][j] == 0){
				dp[1][j] = 1;
			}
		}
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (field[i][j] == 1){
					continue;
				}
				if (field[i][j] == 2){
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				if (field[i + 1][j - 1] == 0){
					dp[i + 1][j - 1] += dp[i][j];
				}
				if (field[i + 1][j] != 1){
					dp[i + 1][j] += dp[i][j];
				}
				if (field[i + 1][j + 1] == 0){
					dp[i + 1][j + 1] += dp[i][j];
				}
			}
		}

		// for (int i = 0; i <= y; i++){
		// 	for (int j = 0; j <= x; j++){
		// 		cout << dp[i][j] << " ";
		// 	}
		// 	puts("");
		// }

		int ret = 0;
		for (int i = y - 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (i == y - 1){
					if (field[i][j] == 2) ret += dp[i][j];
					continue;
				}
				else {
					ret += dp[i][j];
					// cout << i << " " << j << endl;
					// cout << ret << endl;
				}
			}
		}
		cout << ret << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;


int main() {
	while(1) {
		int x, y;
		cin >> y >> x;
		if(x==0 && y==0) break;
		int field[x][y];
		for(int i=0; i<x; i++) {
			for(int j=0; j<y; j++) {
				cin >> field[i][j];
			}
		}
		int dp[x+1][y];
		for(int i=0; i<x+1; i++) {
			for(int j=0; j<y; j++) {
				dp[i][j] = 0;
			}
		}
		for(int i=0; i<x; i++) {
			for(int j=0; j<y; j++) {
				if(i==0 && field[i][j] == 0) dp[i][j] = 1;
				else {
					if(field[i][j] == 0) {
						if(0<j && field[i-1][j-1] == 0) dp[i][j] += dp[i-1][j-1];
						if(field[i-1][j] == 0) dp[i][j] += dp[i-1][j];
						if(j<y-1 && field[i-1][j+1] == 0) dp[i][j] += dp[i-1][j+1];
					}
					if(field[i][j] == 2) {
						if(field[i-1][j] == 0) dp[i][j] += dp[i-1][j];
						dp[i+2][j] += dp[i][j];
					}
				}
			}
		}
		for(int i=0; i<y; i++) dp[x][i] += dp[x-1][i];

		int sum=0;
		for(int i=0; i<y; i++) sum += dp[x][i];
		cout << sum << endl;

		//cout << endl;
		//for(int i=0; i<x+1; i++) {
			//for(int j=0; j<y; j++) {
				//cout << dp[i][j] << ' ';
			//}
			//cout << endl;
		//}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int w,h,xd[]={1,0,-1},p,u[20][20],d[20][20];
int ret(int x,int y){
	int s=x,sum=0;
	if(h-1<=y){
		return 1;
	}
	if(d[y][x]>=1)
	return d[y][x];
	else if(u[y][x]==2)
		return d[y][x]=ret(x,y+2);
	else if(u[y][x]==0){
		y++;
		for(int i=0;i<3;i++){
			x=s+xd[i];
			if(x>=0&&x<=w-1){
				if(u[y][x]==2&&i==1)
					sum+=d[y-1][s]=ret(x,y+2);
				else if(u[y][x]==0)
					sum+=d[y-1][s]=ret(x,y);
			}
		}
		return d[y-1][s]=sum;
	}
	return d[y][s]=-1;
}
int main(){
	int x,y;
	while(cin>>w>>h,w||h){
		p=0;
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			cin>>u[i][j];
			d[i][j]=0;
		}
		for(int i=0;i<w;i++){
			if(u[0][i]==0){
				x=i;
				y=0;
				p+=ret(x,y);
			}
			else if(u[0][i]==2){
				x=i;
				y=2;
				p+=ret(x,y);
			}
		}
		cout<<p<<endl;
	}
	return 0;
}