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 <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

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

int d[30][30];
int w, h;
ll dp[30][30];

bool isOutOfRange(int x){
	if(x < 0 || x >= w) return true;
	return false; 
}

int main(){
	while(1){
		w = in.nextInt();
		h = in.nextInt();
		if(w == 0 && h == 0) break;
		rep(i, 30) rep(j, 30) d[i][j] = 0, dp[i][j] = 0LL;
		rep(i, h) rep(j, w){
			d[i][j] = in.nextInt();
		}
		rep(i, w) if(d[0][i]!=1) dp[0][i] = 1;
		for(int i = 0; i < h-1; i++){
			for(int j = 0; j < w; j++){
				if(d[i][j]==0){
					for(int k = 0; k < 3; k++){
						int nx = j + dx[k], ny = i + dy[k];
						if(d[ny][nx]==0){
							dp[ny][nx] += dp[i][j];
						}
					}
					if(d[i + 1][j] == 2){
						dp[i + 3][j] += dp[i][j];
					}
				}
				else if(d[i][j]==2){
					dp[i+2][j] += dp[i][j];
				}
			}
		}
		// for(int i = 0; i < h; i++){
		// 	for(int j = 0; j < w; j++){
		// 		cout<<" "<<d[i][j];
		// 	}
		// 	cout<<endl;
		// }
		// cout<<endl;
		// for(int i = 0; i < h + 1; i++){
		// 	for(int j = 0; j < w; j++){
		// 		cout<<" "<<dp[i][j];
		// 	}
		// 	cout<<endl;
		// }
		ll ans = 0LL;
		for(int i = 0; i < w; i++){
			ans += dp[h][i];
			ans += dp[h-1][i];
		}
		cout<<ans<<endl;
	}
}

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 >> W >> H;
		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>
using namespace std;

int main() {
	int X, Y;
	const int M = 2;
	while(cin >> X >> Y, X || Y) {
		long long table[128][128];
		int m[128][128];
		for(int i = 0; i < 128; i++) {
			for(int j = 0; j < 128; j++) {
				table[i][j] = 0;
				m[i][j] = 1;
			}
		}
		for(int i = M; i < Y + M; i++) {
			for(int j = M; j < X + M; j++) {
				int tmp;
				cin >> tmp;
				m[i][j] = tmp;
			}
		}

		for(int i = M; i < X + M; i++) {
			m[M-1][i] = 0;
			m[M+Y][i] = 0;
			m[M+Y+1][i] = 0;
			if(m[M][i] != 1)
				table[M][i] = 1;
		}

		for(int i = M; i < Y + M; i++) {
			for(int j = M; j < X + M; j++) {
				int dx[] = {-1, 0, 1};
				for(int k = 0; k < 3; k++) {
					if(m[i][j] == 2 && dx[k] == 0) {
						if((m[i + 2][j] == 2) || (m[i + 2][j] == 0))
							table[i + 2][j] += table[i][j];
					}
					else if(m[i][j] == 0) {
						if(((m[i + 1][j + dx[k]] == 2 && dx[k] == 0) || (m[i + 1][j + dx[k]] == 0)) && (i != Y + M - 1 || dx[k] == 0))
							table[i + 1][j + dx[k]] += table[i][j];
					}
				}
			}
		}

		/*
		for(int i = 0; i < Y + 2*M + 2; i++) {
			for(int j = 0; j < X + M*2; j++) {
				cout << table[i][j] << " ";
			}
			cout << endl;
		}
		*/

		long long ans = 0;
		for(int i = M; i < X + M; i++) {
			ans += table[Y+M][i];
			ans += table[Y+M+1][i];
		}
		cout << ans << endl;
	}
}