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 <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;


signed main() {
	int y, x;
	while (1) {
		cin >> y >> x;
		if (y + x == 0) break;
		int d[20][20] = { -1 };
		rep(i, 0, y) {
			rep(j, 0, x) {
				cin >> d[i][j];
			}
		}
		int dp[20][20] = { 0 };
		rep(i, 0, x) {
			if (d[0][i] == 0) dp[0][i] = 1;
		}
		rep(i, 0, y) {
			rep(j, 0, x) {
				if (d[i][j] == 1) continue;
				if (d[i][j] == 2) {
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				rep(k, -1, 2) {
					if (j + k < 0 || j + k >= x || d[i + 1][j + k] != 0) continue;
					dp[i + 1][j + k] += dp[i][j];
				}
				if (d[i + 1][j] == 2) {
					dp[i + 1][j] += dp[i][j];
				}
			}
		}
		/*cout << endl;
		rep(i, 0, y + 2) {
			rep(j, 0, x) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		int ans = 0;
		rep(i, 0, x) {
			ans += dp[y - 1][i];
			/*if (d[y - 2][i] == 2) {
				ans += dp[y - 2][i];
			}*/
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
int solve(int x,int y);
int ax,ay;
int mas[50][50];
int memo[50][50];
int main(){
  while(1){
    int ans=0;
    for(int i=0;i<16;i++){
      for(int j=0;j<16;j++){
	memo[i][j]=0;
      }
    }
    cin>>ax>>ay;
    if(ax==0 && ay==0){
      break;
    }
    for(int i=0;i<ay;i++){
      for(int j=0;j<ax;j++){
	cin>>mas[i][j];
      }
    }
    for(int i=0;i<ax;i++){
      if(mas[0][i]!=1){
	ans+=solve(i,0);
      }
    }
    cout<<ans<<endl;
  }
}
int solve(int x,int y){
  if(memo[y][x]!=0){
    return memo[y][x];
  }
  else if(y==ay){
    return 1;
  }else if(mas[y][x]==1){
    return 0;
  }else if(mas[y][x]==2){
    return solve(x,y+2);
  } 
  else{
    int anss=0; 
    if(mas[y+1][x]!=1){
      anss+=solve(x,y+1);
    }
    if(x+1<ax && mas[y+1][x+1]==0 && y+1!=ay){
      anss+=solve(x+1,y+1);
    }
    if(0<=x-1 && mas[y+1][x-1]==0 && y+1!=ay){
      anss+=solve(x-1,y+1);
    }
    return memo[y][x]=anss;
  }
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={-1,0,1};
int X,Y;
int board[20][20];
int cnt;
void dfs(int y,int x){
	while(board[y][x]==2){
		y+=2;
	}
	if(y>=Y){
		cnt++;
		//printf("(y,x) =(%d,%d)\n",y,x);
		return;
	}
	
	//cout <<"y = "<<y <<" x = "<<x<<endl;
	for(int i =0; i<3;i++){
		int nx =x +dx[i];
		int ny =y +1;
		if(nx <1||nx>X)continue;
		if(i!=1&&board[ny][nx]==2)continue;
		if(board[ny][nx]==1)continue;
		if(board[ny][nx]==0||board[ny][nx]==2){
			dfs(ny,nx);
		}
	}
	return;
}

int main(){
	while(cin>>X>>Y,X||Y){
		cnt =0;
		rep(i,20)rep(j,20)board[i][j]=0;
		for(int i=1;i <=Y;i++){
			for(int j =1;j <=X;j++){
				cin>>board[i][j];
			}
		}
		for(int i =1;i <=X;i++){
			if(board[1][i]==0){
				dfs(1,i);
			}
			//cout <<endl;
		}
		cout <<cnt<<endl;
	}
	
}

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

int DP[17][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+1; 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+1; i++)
			for(int k=1; k<=x; k++)
				ans += DP[i][k];
		cout << ans << endl;
	}
}

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(y >= Y-1) return 1;
	if(memo[y][x] != -1) return memo[y][x];
	if(Fld[y][x] == 2) return DFS(y+2, 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){
		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] != 1) ans += DFS(0, i);
		printf("%d\n", ans);
	}
	return 0;
}