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];
			ans += dp[h+1][i];
			ans += dp[h+2][i];
		}
		cout<<ans<<endl;
	}
}

C++: #include<iostream>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int main() {
  while (true) {
    int x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) break;
    int c[20][20];
    rep (i, y) rep (j, x) cin >> c[i][j];
    long long dp[20][20][3] = {};
    rep (i, x) if (c[0][i] == 0) dp[0][i][1] = 1;
    rep (i, y - 1) rep (j, x) {
      if (c[i][j] == 0) {
	long long sum = dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
	if (j > 0 && c[i + 1][j - 1] != 2) dp[i + 1][j - 1][0] += sum;
	dp[i + 1][j][1] += sum;
	if (c[i + 1][j + 1] != 2) dp[i + 1][j + 1][2] += sum;
      } else if (c[i][j] == 2) {
	dp[i + 2][j][1] += dp[i][j][1];
      }
    }
    long long res = 0;
    rep (i, x) if (c[y - 1][i] != 1) rep (k, 3) res += dp[y - 1][i][k];
    rep (i, x) res += dp[y][i][1];
    cout << res << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    while (1) {
        int dp[17][17] = { 0 };
        int field[17][17] = { 0 };
        int h, w;

        cin >> w >> h;
        if (w == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> field[i][j];
            }
        }
        for (int j = 0; j < w; j++) {
            if (field[0][j] != 1) {
                dp[0][j] = 1;
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (dp[i][j] > 0) {
                    if (field[i][j] == 0) {
                        if (i != h - 1 && j != 0 && 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 != h - 1 && j != w - 1 && field[i + 1][j + 1] == 0) {
                            dp[i + 1][j + 1] += dp[i][j];
                        }
                    }
                    else if (field[i][j] == 2) {
                        if (i == h - 1) {
                            dp[i + 1][j] += dp[i][j];
                        }
                        else if (field[i + 2][j] != 1){
                            dp[i + 2][j] += dp[i][j];
                        }
                    }
                }
            }
        }
        
        int ans = 0;
        for (int j = 0; j < w; j++) {
            ans += dp[h][j];
        }
        cout << ans << endl;
    }
    
    return 0;
}