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<queue>
#include<map>
#include<algorithm>
using namespace std;
int vx[3]={-1,0,1};
int main(){
  int x,y;
  while(cin>>y>>x,x+y!=0){
    int Map[y+5][x+5]={0};
    int cnt=0;
    for(int i=1;i<=y;i++)
      for(int j=1;j<=x;j++)
	cin>>Map[i][j];
    queue<pair<int,int> >qii;
    for(int i=1;i<=x;i++){
      if(Map[1][i]!=1)
	qii.push(make_pair(1,i));
    }
    while(!(qii.empty())){
      pair<int,int>now = qii.front();
      qii.pop();
      
      if(now.second<1||now.second>x)
	continue;
      if(now.first > y-1){
	cnt++;
	continue;
      }
      switch(Map[now.first][now.second]){
      case 0:
	for(int i=0;i<3;i++){
	  if(Map[now.first+1][now.second+vx[i]]==0)
	    qii.push(make_pair(now.first+1,now.second+vx[i]));
	}
	if(Map[now.first+1][now.second]==2)
	  qii.push(make_pair(now.first+1,now.second));
	  break;
	case 2:
	  if(Map[now.first+2][now.second]!=1)
	    qii.push(make_pair(now.first+2,now.second));
	  break;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int x,y;
int fie[20][20];
long long int dp[20][20];
long long int ans=0;

int main(void){
	while(1){
		scanf("%d%d",&x,&y);
		if(x==0 && y==0)break;
		memset(fie,0,sizeof(fie));
		memset(dp,0,sizeof(dp));
		ans=0;

		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				scanf("%d",&fie[j][i]);
			}
		}
		for(int i=0;i<x;i++){
			if(fie[i][0]==0)dp[i][0]=1;
			if(fie[i][0]==2)dp[i][2]=1;
		}
		for(int i=0;i<y;i++){
			for(int j=0;j<x;j++){
				if(fie[j][i]==0){
					for(int k=j-1;k<=j+1;k++){
						if(k>=0 && k<x){
							if(fie[k][i+1]==0){
								dp[k][i+1]+=dp[j][i];
							}
							if(fie[k][i+1]==2 && k==j){
								dp[k][i+1]+=dp[j][i];
							}
						}
					}
				}
				if(fie[j][i]==2){
					dp[j][i+2]+=dp[j][i];
				}
			}
		}
		for(int i=0;i<y;i++){
				for(int j=0;j<x;j++){
					if(i>=y-2 && fie[j][i]==2)ans+=dp[j][i];
					if(i==y-1 && fie[j][i]==0)ans+=dp[j][i];
			}
		}
		printf("%lld\n",ans);
	}
    return 0;
}

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

int main() {
	int x, y;
	while (cin >> x >> y ,x,y) {
		vector<vector<int>> course(y + 2, vector<int>(x + 2, 0));
		for (int i = 1; i <= y; i++) {
			for (int j = 1; j <= x; j++) {
				cin >> course[i][j];
			}
		}

		vector<vector<int>> path(y + 2, vector<int>(x + 2, 0));
		//?????????????????????????????????1????????????
		for (int i = 1; i <= x; i++) {
			if (course[1][i] != 1) path[1][i] = 1;
		}

		for (int i = 1; i <= y; i++) {
			for (int j = 1; j <= x; j++) {
				//????????????????????´????????????????????´??????????????????????????????????????????
				//?????????????§????????????????????????´?????????????????????????????£????????°?????´????????????????????????
				if (course[i][j] == 0) {
					if (course[i + 1][j + 1] == 0) path[i + 1][j + 1] += path[i][j];
					if (course[i + 1][j] != 1) path[i + 1][j] += path[i][j];
					if (course[i + 1][j - 1] == 0) path[i + 1][j - 1] += path[i][j];
				}
				//?¬???????????????´???????????£????????°????????????????????????????????????
				//?????????????????£????????§??´??????????????´???????????????(?????£?????????????????????????????´???????????????)
				if (course[i][j] == 2 && course[i + 2][j] != 1) {
					path[i + 2][j] += path[i][j];
					if (i + 2 > y && i != y) path[y][j] += path[i][j];
				}
				//???????????´???????????????????????????????????????
				if (course[i][j] == 1) {/*do anything*/ }
			}
		}

		cout << accumulate(path[y].begin() + 1, path[y].end() - 1, 0) << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
	int x,y;
	while(cin >> x >> y, x|y){
		vvi field(y,vi(x));
		REP(i,y){
			REP(j,x){
				cin >> field[i][j];
			}
		}
		vvi dp(y,vi(x,0));
		REP(i,y){
			REP(j,x){
				if(i==0&&field[i][j]==0){
					dp[i][j]=1;
				}
				if(i<y-1&&field[i][j]==0){
					if(j>0&&field[i+1][j-1]==0){
						dp[i+1][j-1]+=dp[i][j];
					}
					if(j<x-1&&field[i+1][j+1]==0){
						dp[i+1][j+1]+=dp[i][j];
					}
					if(field[i+1][j]!=1){
						dp[i+1][j]+=dp[i][j];
					}
				}
				if(i<y-2&&field[i][j]==2){
					if(field[i+2][j]!=1){
						dp[i+2][j]+=dp[i][j];
					}
				}
			}
		}
		int result=0;
		REP(i,x){
			result+=dp[y-1][i];
			if(field[y-2][i]==2){
				result+=dp[y-2][i];
			}
		}
		cout << result << endl;
	}
return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
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 = 50;
const int MAX_X = 50;
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) res = 1;
  
  if (c[y][x] == 2 && c[y+2][x] != 1) {
    if (y + 2 >= my - 1) {
      res = 1;
    } else {
      if (c[y+2][x] != 1) res += dfs(y+2, x);
    }
  }
  
  if (res != 0) 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);
  }
  /*
  rep(i,my) {
    rep(j,mx) printf("%8d",dp[i][j]);
    cout<<endl;
  }*/
  cout<<res<<endl;
}

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