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 main(){
	int w,h;

	while( cin >> w >> h , w||h ){
		int f[20][20] = {0};
		for(int y=1 ; y <= h ; y++ ){
			for(int x=1 ; x <= w ; x++ ){
				cin >> f[y][x];
			}
		}

		int dp[20][20] = {0};
		for(int x=1 ; x <= w ; x++ )
			dp[1][x] = 1;
		for(int y=1 ; y <= h-1 ; y++ ){
			for(int x=1 ; x <= w ; x++ ){
				if( f[y][x] == 0 ){
					if( f[y+1][x-1] == 0 ) dp[y+1][x-1] += dp[y][x];
					if( f[y+1][x]   == 0 ) dp[y+1][x]   += dp[y][x];
					if( f[y+1][x+1] == 0 ) dp[y+1][x+1] += dp[y][x];
					if( f[y+1][x]   == 2 ) dp[y+1][x]   += dp[y][x];
				}else if( f[y][x] == 2 ){
					if( f[y+2][x] == 0 ) dp[y+2][x] += dp[y][x];
					if( f[y+2][x] == 2 ) dp[y+2][x] += dp[y][x];
				}
			}
		}
		int ans = 0;
		for(int x=1 ; x <= w ; x++ ){
			ans += dp[h][x] + dp[h+1][x];
		}
		cout << ans << endl;
	}
}

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

const int MAX = 15;
const int dx[] = {-1, 0, 1};
int X, Y;
int c[MAX + 2][MAX + 2], dp[MAX + 2][MAX + 2];

int main()
{
    while(cin >> X >> Y && X) {
        for(int i = 1; i <= Y; i++)
            for(int j = 1; j <= X; j++)
                cin >> c[i][j];

        memset(dp, 0, sizeof(dp));
        for(int j = 1; j <= X; j++) 
            dp[1][j] = (c[1][j] == 0) ? 1 : 0;
        
        for(int i = 2; i <= Y; i++) {
            for(int j = 1; j <= X; j++) {
                if(c[i][j] == 0) {
                    for(int k = 0; k < 3; k++)
                        if(c[i - 1][j + dx[k]] == 0)
                            dp[i][j] += dp[i - 1][j + dx[k]];
                } else if(c[i][j] == 1) {
                    dp[i][j] = 0;
                } else {
                    if(dp[i][j] == 0) 
                        dp[i][j] = dp[i - 1][j];
                    dp[i + 2][j] = dp[i][j];
                }
            }
        }
        
        int ans = 0;
        for(int j = 1; j <= X; j++) 
            if(dp[Y + 1][j] > 0)
                ans += dp[Y + 1][j];
            else 
                ans += dp[Y][j];

        cout << ans << endl;
        
    }
}

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())
int w,h;
int grid[15][15];
int memo[15][15];
int dfs(int x,int y){
  if(x<0||x>=w) return 0;
  if(y<0||y>=h) return 0;
  if(grid[y][x]==1) return memo[y][x] = 0;
  if(y==0) return memo[y][x] = 1;
  if(memo[y][x]>=0){
    return memo[y][x];
  }
  int ret = 0;
  if(grid[y-1][x]!=2)ret += dfs(x,y-1);
  if(grid[y][x]!=2&&x-1>=0&&grid[y-1][x-1]!=2)ret += dfs(x-1,y-1);
  if(grid[y][x]!=2&&x+1<w&&grid[y-1][x+1]!=2)ret += dfs(x+1,y-1);
  if(y>=2&&grid[y-2][x]==2) ret += dfs(x,y-2);
  return memo[y][x] = ret;
}

int main(void){
  while(cin>>w>>h,w){
    memset(memo,-1,sizeof(memo));
    REP(y,h)REP(x,w){
      cin>>grid[y][x];
    }
    int ans = 0;
    REP(x,w){
      ans += dfs(x,h-1);
      if(grid[h-2][x]==2) ans += dfs(x,h-2);
    }
    
    cout<<ans<<endl;
  }
  return 0;
}

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

C++: #include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int m[500][500];
int dp[500][500];

int dx[]={-1,0,1};

int solve(int r,int c){
  rep(i,r+2)rep(j,c)dp[i][j]=0;
  rep(j,c)if(m[0][j] == 0)dp[0][j]=1;

  rep(i,r){
    rep(j,c){
      if (m[i][j] == 0 && i != r-1){
	rep(k,3){
	  int nex = j+dx[k];
	  if (nex<0||nex>=c)continue;
	  if (m[i+1][nex] == 0)dp[i+1][nex]+=dp[i][j];
	  else if (m[i+1][nex] == 2 && k == 1)dp[i+1][nex]+=dp[i][j];
	}
      }else if (m[i][j] == 2){
	dp[i+2][j]+=dp[i][j];
      }
    }
  }
  
  int ans = 0;
  rep(j,c)ans+=dp[r][j]+dp[r-1][j]+dp[r+1][j];
  return ans;
}

main(){
  int c,r;
  while(cin>>r>>c && r){
    rep(i,r)rep(j,c)cin>>m[i][j];
    rep(j,c)m[r][j]=m[r+1][j]=0;
    cout << solve(r,c) << endl;
  }
}