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<cstring>
 
#define rep(i,n) for(int i = 1; i <= n; i++)
 
#define MS   (15)
#define CM   (0)
#define TREE (1)
#define JUMP (2)
 
using namespace std;
 
int x, y;
int map[MS+1][MS+1];
int dp[MS+1][MS+1];
 
void check()
{
        rep(i,y-1) rep(j,x){
                if(map[i][j] == CM){
                        if(map[i+1][j] != TREE)  { dp[i+1][j]  +=dp[i][j]; }
                        if((j+1)<=x){
                                if(map[i+1][j+1]==CM){ dp[i+1][j+1]+=dp[i][j]; }
                        }
                        if((j-1)>=1){
                                if(map[i+1][j-1]==CM){ dp[i+1][j-1]+=dp[i][j]; }
                        }
                }
                if(map[i][j] == JUMP){
                        if(i+2 > y){
                                dp[y][j] += dp[i][j];
                        }
                        else if(map[i+2][j] != TREE){
                                dp[i+2][j]+=dp[i][j];
                        }
                }
        }
 
}
 
int main(void)
{
 
        while(cin >> x >> y && x){
                rep(i,y) rep(j,x){
                        cin >> map[i][j];
                }
 
                memset(dp, 0, sizeof(dp));
                
                rep(i,x)
                        if(map[1][i] != TREE){ dp[1][i]++; }
                
                check();
                
                int sum=0;
                
                rep(i,x){ sum += dp[y][i]; }
                
                cout << sum << endl;
                
        }
 
        return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,m;
  while(cin>>m>>n,n||m){
    vector<vector<int> >in(n,vector<int>(m));
    vector<vector<int> >dp(n+1,vector<int>(m));
    rep(i,n)rep(j,m)cin>>in[i][j];
    rep(i,m)dp[0][i]=1;
    loop(i,1,n+1){
      rep(j,m){
	if(i<n&&in[i][j]==1)continue;
	else if(i!=n){
	  if(j!=0&&in[i-1][j-1]==0&&in[i][j]!=2)dp[i][j]+=dp[i-1][j-1];
	  if(in[i-1][j]==0)dp[i][j]+=dp[i-1][j];
	  if(j!=m&&in[i-1][j+1]==0&&in[i][j]!=2)dp[i][j]+=dp[i-1][j+1];
	  if(i!=1&&in[i-2][j]==2)dp[i][j]+=dp[i-2][j];
	}else if(i-2>=0&&in[i-2][j]==2)dp[i][j]+=dp[i-2][j];
      }      
    }
    int sum=0;
    //rep(i,n+1){rep(j,m)printf(" %2d",dp[i][j]);puts("");}
    loop(i,n-1,n+1)rep(j,m)sum+=dp[i][j];
    cout<<sum<<endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
  int W, H, mas[16][16];
  while( cin >> W >> H, W){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> mas[i][j];
      }
    }
    vector< vector< int > > dp( H + 1, vector< int >(W, 0));
    for(int i = 0; i < W; i++){
      if(mas[0][i] != 1) dp[0][i] = 1;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(dp[i][j] == 0) continue;
        if(mas[i][j] == 0){
          for(int k = -1; k <= 1; k++){
            if(j + k < 0 || j + k >= W) continue;
            if((i == H - 1 && k == 0) || (i != H - 1 && k == 0 && mas[i + 1][j + k] == 2) || (i != H - 1 && mas[i + 1][j + k] == 0)){
              dp[i + 1][j + k] += dp[i][j];
            }
          }
        } else if(mas[i][j] == 2){
          if(i >= H - 2 || mas[i + 2][j] != 1){
            dp[min(H, i + 2)][j] += dp[i][j];
          }
        }
      }
    }

    int ret = 0;
    for(int i = 0; i < W; i++){
      ret += dp[H][i];
    }
    cout << ret << endl;
  }
}

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

int dmap[15][15];
int dpmap[15][15];
int dfs(int, int, int);
int dx[]={-1, 0, 1};
int h, w;

int main(){
  while(1){
    cin >> w >> h;
    if(w==0 && h==0) break;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> dmap[i][j];
      }
    }


    int ans=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	dpmap[i][j]=-1;
      }
    }
    for(int i=0;i<w;i++){
      if(dmap[0][i]==0){
	int tmp=dfs(0,i,1);
	if(tmp>0) ans+=tmp;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

int dfs(int y, int x, int d){
  int sum=0;
  if(y>=h){
    return 1;
  }
  else if(dmap[y][x]==1){
    dpmap[y][x]=0;
    return 0;
  }
  else if(dmap[y][x]==2){
    if(d==1){
      if(y==h-2){
	dpmap[y][x]=1;
	return 1;
      }
      if(dpmap[y+2][x]!=-1){
	sum+=dpmap[y+2][x];
	dpmap[y][x]=sum;
	return sum;
      }
      else{
	sum+=dfs(y+2, x, 1);
	dpmap[y][x]=sum;
	return sum;
      }
    }
    else{
      return 0;
    }
  }
else if(y==h-1){
    sum+=dfs(y+1, x, 1);
    dpmap[y][x]=sum;
    return sum;
  }
 else{
    for(int i=0;i<3;i++){
      int tx=x+dx[i];
      int ty=y+1;
      if(tx<0 || tx>=w) continue;
      if(dmap[ty][tx]==1) continue;
      if(dmap[ty][tx]==2 && i!=1) continue;
      if(dpmap[ty][tx]!=-1){
	sum+=dpmap[ty][tx];
      }
      else sum+=dfs(ty, tx, i);
    }
  }
  dpmap[y][x]=sum;
  return sum;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
const int MAX_Y = 30;
const int MAX_X = 30;
int mx, my, c[MAX_Y][MAX_X], dp[MAX_Y][MAX_X];

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

int dfs(int y, int x) {  
  int res = 0;
  if (dp[y][x] >= 0) return dp[y][x];
  
  if (y == my - 1) return 1;
  
  if (c[y][x] == 2) {
    if (y+2 >= my - 1) return 1;
    res += dfs(y+2, x);
    return dp[y][x] = res;
  }
  
  rep(z,3) {
    int tx = x + dx[z], ty = y + dy[z];
    if (tx < 0 || ty < 0 || tx >= mx || ty >= my) continue;
    if (c[ty][tx] == 1) continue;
    if (c[ty][tx] == 2 && tx != x) continue;
    res += dfs(ty, tx);
  }

  return dp[y][x] = res;
}

void solve() {
  memset(dp, -1, sizeof dp);
  rep(i,my) rep(j,mx) cin>>c[i][j];

  int res = 0;
  rep(i,mx) {
    if (c[0][i] == 1) continue;
    res += dfs(0, i);
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>mx>>my, mx||my) {
    solve();
  }
  return 0;
}