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 w, h, c[15][15];
int res;

void dfs(int x, int y) {
	if (y <= h-1 && c[y][x] == 1) return;
	if (y >= h-1) {
		++res;
		return;
	}
	if (c[y][x] == 0) {
		for (int i = 0; i < 3; ++i) {
			int nx = x + i - 1, ny = y + 1;
			if (0 <= nx && nx < w && ((x == nx && c[ny][nx] == 2) || c[ny][nx] == 0)) dfs(nx, ny);
		}
	}
	if (c[y][x] == 2) dfs(x, y+2);
	return;
}

int main(void) {
	while (cin >> w >> h, w && h) {
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) cin >> c[i][j];
		}
		res = 0;
		for (int i = 0; i < w; ++i) {
			if (c[0][i] == 0) dfs(i, 0);
		}
		cout << res << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
typedef long long ll;
int x, y;
ll dp[15][15];
int mp[15][15];
int main() {
  while (scanf("%d%d",&x,&y)) {
    if (!x&&!y) break;
    memset(dp, 0, sizeof(dp));
    memset(mp, 0, sizeof(mp));
    for (int i=0; i<y; i++) {
      for (int j=0; j<x; j++) scanf("%d",&mp[i][j]);
    }
    for (int i=0; i<x; i++) if (mp[0][i]!=1) dp[0][i]=1;
    ll res = 0;
    for (int i=0; i<y-1; i++) {
      for (int j=0; j<x; j++) {
        if (mp[i][j]==2) {
          if (i+2>=y) res+=dp[i][j];
          else dp[i+2][j]+=dp[i][j];
        } else {
          if (j!=0&&mp[i+1][j-1]==0) dp[i+1][j-1]+=dp[i][j];
          if (mp[i+1][j]!=1) dp[i+1][j]+=dp[i][j];
          if (j!=x-1&&mp[i+1][j+1]==0) dp[i+1][j+1]+=dp[i][j];
        }
      }
    }
    for (int i=0; i<x; i++) res+=dp[y-1][i];
    printf("%lld\n",res);
  }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt"

int main() {
	while (1) {
		int H, W; cin >> H >> W;
		if (!H)break;
		vector<vector<int>>field(H + 3, vector<int>(W + 2,1));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cin >> field[i][j+1];
			}
		}
		for (int i = H; i < H + 3; ++i) {
			for (int j = 1; j <= W; ++j) {
				field[i][j] = 0;
			}
		}
		vector<vector<long long int>>nums(H + 3, vector<long long int>(W + 2, 0));
		for (int j = 0; j < W + 2; ++j) {
			if (!field[0][j])nums[0][j] = 1;
		}
		long long int ans = 0;
		for (int i = 0; i < H; ++i) {
			for (int j = 1; j < W + 1; ++j) {
				for (int dx = -1; dx <= 1;++dx) {
					const int nextx = j + dx;
					int nexty = i + 1;
					
					if (field[nexty][nextx] == 1) {

					}
					else if (field[nexty][nextx] == 2) {
						if (!dx) {
							while (1) {
								nexty += 2;
								if (nexty >= H - 1 && field[nexty][nextx] != 1) {
									ans += nums[i][j];
									break;
								}
								else {
									if (field[nexty][nextx] == 1) {
										break;
									}
									else if (field[nexty][nextx] == 0) {

										nums[nexty][nextx] += nums[i][j];
										break;
									}
								}
							}
							
						}
					}
					else {
						if (nexty >= H - 1)ans += nums[i][j];
						else {
							nums[nexty][nextx] += nums[i][j];
						}
					}
				}
				
			}
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int field[16][16];
// y,xÌ}X©çènßÄÅ«é·×èûÌ
int dp[16][16];

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

int search(int sx,int sy){
	if(field[sy][sx]==2){
		if(sy>=h-2){
			return 1;
		}
		else if(field[sy+2][sx]==1)
			return 0;
		else{
			return search(sx,sy+2);
		}
	}
	if(dp[sy][sx]!=-1){
		return dp[sy][sx];
	}
	int cnt=0;
	for(int i = 0; i < 3; i++){
		int nx=sx+dx[i];
		int ny=sy+dy[i];
		if(nx>=0&&nx<w){
			if(ny>h-1){
				cnt++;
			}
			else if(ny==h-1&&field[ny][nx]==0){
				cnt++;
			}
			else if(field[ny][nx]==2&&dx[i]==0){
				cnt+=search(nx,ny);
			}
			else if(field[ny][nx]==0){
				cnt+=search(nx,ny);
			}
		}
	}

	dp[sy][sx]=cnt;
	return dp[sy][sx];
}


int main(){

	while(cin>>w>>h&&!(w==0&&h==0)){
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				cin>>field[i][j];
				dp[i][j]=-1;
			}
		}
		int sum=0;
		for(int i = 0; i < w; i++){
			if(field[0][i]==0)
				sum+=search(i,0);
		}
		cout<<sum<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
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 X, Y;
int ba[15][15];

int const dx[] = {-1,0,1};
int solve(int x, int y) {
  if (y >= Y-1) return 1;
  int res = 0;
  REP(i,3) {
    int xx = x + dx[i];
    int yy = y+1;
    
    if (xx < 0 || X <= xx) continue;
    if (i == 1) {
      while (yy < Y && ba[xx][yy] == 2) {
        yy+=2;
      }
      if (yy >= Y || ba[xx][yy] == 0)
        res += solve(xx, yy);
    } else if (ba[xx][yy] == 0) {
      res += solve(xx, yy);
    }
  }
  return res;
}

int main() {
  while(cin >> X >> Y, X||Y) {
    REP(y,Y) {
      REP(x,X) {
        cin >> ba[x][y];
      }
    }
    int ans = 0;
    REP(x,X) {
      ans += solve(x, 0);
    }
    cout << ans << endl;
  }
}