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 <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  
  int X, Y;
  int const dx[] = {0,-1,1};
  
  while(cin >> X >> Y, X||Y) {
    int ba[X][Y];
    REP(y,Y) {
      REP(x,X) {
        cin >> ba[x][y];
      }
    }
    int dp[X][Y];
    memset(dp,0,sizeof(dp));
    REP(i,X)
      if (ba[i][0] == 0)
        dp[i][0] = 1;
    REP(y, Y-1) {
      REP(x,X) {
        if (ba[x][y] == 0) {
          REP(i,3) {
            int xx = x + dx[i];
            int yy = y + 1;
            if (xx < 0 || X <= xx) continue;
            
            if (ba[xx][yy] == 0 || ba[xx][yy] == 2 && i == 0) {
              dp[xx][yy] += dp[x][y];
            }
          }
        } else if (ba[x][y] == 2) {
          if (y+2 < Y && ba[x][y+2] != 1)
            dp[x][y+2] = dp[x][y];
        }
      }
    }
    // REP(y,Y) {
    //   REP(x,X) {
    //     cout << dp[x][y] << " ";
    //   }
    //   cout << endl;
    // }
  
    int ans = 0;
    REP(x,X) {
      ans += dp[x][Y-1];
      if (ba[x][Y-2] == 2)
        ans += dp[x][Y-2];
    }
    cout << ans << endl;
  }
}

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)if(in[0][i]==0)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<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[20][20],f,j,i,k;
	long long int g,h[20][20];
	while(1){
		scanf("%d %d",&a,&s);
		if(a==0&&s==0) break;
		for(i=0;i<s;i++) h[0][i]=1;
		for(i=0;i<a;i++){
			for(j=0;j<s;j++) scanf("%d",&d[i][j]);
		}
		for(i=0;i<s;i++){
			if(d[0][i]==1) h[0][i]=0;
		}
		for(i=1;i<a;i++){
			for(j=0;j<s;j++) h[i][j]=0;
		}
		for(i=0;i<a;i++){
			for(j=0;j<s;j++){
				if(i!=0&&d[i+1][j]==1&&d[i][j]==2){
					if(i+2<a) h[i+2][j]+=h[i][j];
					else h[i+1][j]+=h[i][j];
				}
				if(h[i][j]!=0){
					if(d[i][j]==0) if(j!=0) if(d[i+1][j-1]==0) h[i+1][j-1]+=h[i][j];
					if(j!=s){
						if(d[i][j]==0) if(d[i+1][j+1]==0) h[i+1][j+1]+=h[i][j];
						if(d[i+1][j]==0||d[i+1][j]==2) h[i+1][j]+=h[i][j];
					}
				}
			}
		}
		g=0;
		for(j=0;j<s;j++) g+=h[a-1][j];
		/*printf("\n\n");
		for(i=0;i<a;i++){
			for(j=0;j<s;j++) printf("%d ",h[i][j]);
			printf("\n");
		}*/
		printf("%d\n",g);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){

    int w,h;
    while(cin>>w>>h){
        if(w==0)break;
        int data[16][16]={{0}},dp[17][17]={{0}};
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>data[i][j];
                if(i==0&&data[i][j]!=1)dp[i][j]=1;
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(dp[i][j]!=0){
                    if(data[i][j]==0){
                        if(i!=h-1&&j!=0&&data[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
                        if(data[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
                        if(i!=h-1&&j!=w-1&&data[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
                    }
                    else if(data[i][j]==2){
                        if(i==h-1)dp[i+1][j]+=dp[i][j];
                        else if(data[i+2][j]!=1)dp[i+2][j]+=dp[i][j];
                    }
                }
            }
        }
        /*
        cout<<endl;
        for(int i=0;i<=h;i++){
            cout<<i<<":";
            for(int j=0;j<w;j++){
                cout<<dp[i][j]<<" ";
            }
            cout<<endl;
        }*/
        int ans=0;
        for(int j=0;j<w;j++)ans+=dp[h][j];
        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];
  for( int i = 0;i <= c;i++ ){
	  for( int j = 0;j < r;j++ ){
		  cout << dp[i][j];
	  }
	  cout << endl;
  }
  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;
  }
}