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 <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int X, Y;

bool is_inside(int x, int y){
	if(x < 0 || y < 0 || x >= X || y >= Y){
		return false;
	}
	return true;
}

int main(){
	
	int course[20][20];
	long long int sum[20][20];
	
	while(true){
		cin >> X >> Y;
		
		if(X == 0 && Y == 0){
			break;
		}
		
		for(int i = 0; i < Y; i++){
			for(int j = 0; j < X; j++){
				cin >> course[j][i];
				sum[j][i] = 0;
			}
		}
		
		for(int i = 0; i < X; i++){
			sum[i][0] = 1;
		}
		
		for(int y = 0; y < Y; y++){
			for(int x = 0; x < X; x++){
				if(course[x][y] == 0){
					for(int dx = -1; dx <= 1; dx++){
						if(is_inside(x + dx, y + 1)){
							if((course[x + dx][y + 1] != 2 || dx == 0) && y != 0){
								sum[x + dx][y + 1] += sum[x][y];
							}
						}
					}
				}else if(course[x][y] == 2){
					if(is_inside(x, y + 2)){
						sum[x][y + 2] += sum[x][y];
					}
				}else{
					sum[x][y] = 0;
				}
			}
		}
		
		long long int ans = 0;
		
		for(int i = 0; i < X; i++){
			if(course[i][Y - 1] == 0){
				ans += sum[i][Y - 1];
			}
			if(Y >= 2 && course[i][Y - 2] == 2){
				ans += sum[i][Y - 2];
			}
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cassert>
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-1){
    rep(j,c){
      if (m[i][j] == 0 ){
	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 && m[i+2][j] != 1){
	dp[i+2][j]+=dp[i][j];
      }
    }
  }
  
  int ans = 0;
  rep(j,c)ans+=dp[r][j]+dp[r-1][j];
  return ans;
}

main(){
  int c,r;
  while(cin>>c>>r && r){
    rep(i,r)rep(j,c)cin>>m[i][j];
    rep(j,c)m[r][j]=0;
    cout << solve(r,c) << 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(y<=Y-1&&data[y][x]==1) break;
    if(y>=Y-1) return -2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

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

int fld[17][17];
int cnt[17][17];

int main()
{
	int X,Y,S;
	while(cin >> X >> Y, (X||Y))
	{
		for(int y=0; y<17; y++)
		for(int x=0; x<17; x++)
		{
			fld[y][x] = 3;
			cnt[y][x] = 0;
		}

		for(int y=0; y< Y; y++)
		for(int x=1; x<=X; x++)
		{
			cin >> fld[y][x];
			cnt[y][x] = ((y==0&&fld[y][x]==0)?1:0);
		}

		for(int y=0; y< Y-1; y++)
		for(int x=1; x<=X  ; x++)
		{
			if(fld[y][x]==0)
			{
				if(fld[y+1][x+1]==0) cnt[y+1][x+1]+=cnt[y][x];
				if(fld[y+1][x-1]==0) cnt[y+1][x-1]+=cnt[y][x];
				if(fld[y+1][x  ]!=1) cnt[y+1][x  ]+=cnt[y][x]; 
			}
			if(fld[y][x]==2&&fld[y+2][x]!=1)
			{
				cnt[y+2][x]+=cnt[y][x];
			}
		}

		S=0;
		for(int y=Y-1; y< Y+2; y++)
		for(int x=1  ; x<=X  ; x++)
		{
			S+=cnt[y][x];
		}

		cout << S << endl;
	}

	return 0;
}

C++: #include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int x, y;
	while(cin >> x >> y && (x||y) ) {
		int b[15][15] = {};
		rep(i,y) {
			rep(j,x) {
				cin >> b[i][j];
			}
		}
		int ret[20][20] = {};
		rep(i,x) {
			if(b[0][i] == 0) {
				ret[0][i+1] = 1;
			}
		}
		rep2(i,1,y) {
			rep(j,x) {
				if(b[i][j] == 0) {
					ret[i][j+1] += ret[i-1][j] + ret[i-1][j+1] + ret[i-1][j+2];
					rep2(k,-1,1) {
						if(b[i-1][j+k] == 2) ret[i][j+1] -= ret[i-1][j+k+1];
					}
				} else if(b[i][j] == 2) {
					if(b[i+2][j] != 1) ret[i+2][j+1] += ret[i-1][j+1];
				}
			}
		}
		int ans = 0;
		rep2(i,y-1,y+2) {
			rep(j,x) {
				ans += ret[i][j+1];
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[18][18];
int kosu[16][16];
int ans;

int main(){
  int x,y;
  
  while(1){
    cin>>x>>y;
    if(x==0 && y==0) break;
    
    fill(dp[0],dp[18],0);
    ans=0;
    
    for(int i=0;i<y;i++){
      for(int l=0;l<x;l++){
        cin>>kosu[i][l];
      }
    }
    for(int i=0;i<x;i++)
      if(kosu[0][i]==0) dp[0][i]=1;
    
    for(int i=1;i<y;i++){
      for(int l=0;l<x;l++){
        
        if(kosu[i][l]==2){
          dp[i+2][l]=dp[i-1][l]+dp[i-2][l]+dp[i][l];
          dp[i][l]=0;
        }
        else if(kosu[i][l]==0)
          dp[i][l]+=dp[i-1][l-1]+dp[i-1][l]+dp[i-1][l+1];
      }
    }
    
    for(int i=y;i<y+2;i++){
      for(int l=0;l<x;l++){
        dp[i][l]+=dp[i-1][l];
      }
    }
    for(int i=0;i<x;i++)
      ans+=dp[y][i];
    
    printf("%d\n",ans);
  }
  return 0;
}