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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int x, y;
int field[20][20];
int dp[20][20];

int main(){
	while (cin >> x >> y&&x + y){
		REP(i, 16){
			REP(j, 16){
				dp[i][j] = 0;
				field[i][j] = 0;
			}
		}
		REP(i, y)REP(j, x)cin >> field[i][j];
		REP(j, x){
			if (field[0][j] == 0)dp[0][j] = 1;
		}
		REP(i, y - 1){
			REP(j, x){
				if (field[i][j] == 0){
					if (field[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j - 1 >= 0 && field[i + 1][j - 1] == 0){
						dp[i + 1][j - 1] += dp[i][j];
					}
					if (j + 1 < x&&field[i + 1][j + 1] == 0){
						dp[i + 1][j + 1] += dp[i][j];
					}
				}
				else if (field[i][j] == 2){
					if (field[i + 2][j] != 1){
						dp[i + 2][j] += dp[i][j];
					}
				}
			}
		}
		int ans = 0;
		//cout << endl;
		//REP(i, y + 1){
		//	REP(j, x){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		REP(j, x)ans += dp[y - 1][j] + dp[y][j];
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;


int main() {
	while(1) {
		int x, y;
		cin >> y >> x;
		if(x==0 && y==0) break;
		int field[x][y];
		for(int i=0; i<x; i++) {
			for(int j=0; j<y; j++) {
				cin >> field[i][j];
			}
		}
		int dp[x+1][y];
		for(int i=0; i<x+1; i++) {
			for(int j=0; j<y; j++) {
				dp[i][j] = 0;
			}
		}
		for(int i=0; i<x; i++) {
			for(int j=0; j<y; j++) {
				if(i==0 && field[i][j] == 0) dp[i][j] = 1;
				else {
					if(field[i][j] == 0) {
						if(0<j && field[i-1][j-1] == 0) dp[i][j] += dp[i-1][j-1];
						if(field[i-1][j] == 0) dp[i][j] += dp[i-1][j];
						if(j<y-1 && field[i-1][j+1] == 0) dp[i][j] += dp[i-1][j+1];
					}
					if(field[i][j] == 2) {
						dp[i][j] += dp[i-1][j];
						dp[i+2][j] += dp[i][j];
					}
				}
			}
		}
		for(int i=0; i<y; i++) dp[x][i] += dp[x-1][i];
		//int sum=0;
		//for(int i=0; i<y; i++) sum += dp[x][i];
		//cout << sum << endl;

		for(int i=0; i<x+1; i++) {
			for(int j=0; j<y; j++) {
				cout << dp[i][j] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

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

enum FState { PLAIN, TREE, JUMP };
enum PState { LAND, AIR };

int field[17][16];
int dp[17][16][2];

int main() {
  int x, y;
  while (cin >> x >> y, x) {
    for (int yi = 1; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        cin >> field[xi][yi];
      }
      field[0][yi] = field[x + 1][yi] = TREE;
    }

    for (int xi = 1; xi <= x; xi++) {
      dp[xi][1][LAND] = field[xi][1] == TREE ? 0 : 1;
      dp[xi][1][AIR] = 0;
    }
    for (int yi = 2; yi <= y; yi++) {
      for (int xi = 1; xi <= x; xi++) {
        // AIR
        dp[xi][yi][AIR] = field[xi][yi - 1] == JUMP ? dp[xi][yi - 1][LAND] : 0;
        // LAND
        auto& ldp = dp[xi][yi][LAND];
        switch (field[xi][yi]) {
        case PLAIN:
          ldp = dp[xi][yi - 1][AIR];
          for (int offset : {-1, 0, 1}) {
            if (field[xi + offset][yi - 1] == PLAIN) ldp += dp[xi + offset][yi - 1][LAND];
          }
          break;
        case TREE:
          ldp = 0;
          break;
        case JUMP:
          ldp = dp[xi][yi - 1][AIR];
          if (field[xi][yi - 1] == PLAIN) ldp += dp[xi][yi - 1][LAND];
          break;
        }
      }
    }
    
    int r = 0;
    for (int xi = 1; xi <= x; xi++) {
      r += dp[xi][y][LAND] + dp[xi][y][AIR];
    }
    cout << r << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
int x, y;
int 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;
    int res = 0;
    for (int i=0; i<y-1; i++) {
      for (int j=0; j<x; j++) {
        if (mp[i][j]==1) continue;
        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("%d\n",res);
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;


signed main() {
	int y, x;
	while (1) {
		cin >> y >> x;
		if (y + x == 0) break;
		int d[20][20] = { 1 };
		rep(i, 0, y) {
			rep(j, 0, x) {
				cin >> d[i][j];
			}
		}
		int dp[20][20] = { 0 };
		rep(i, 0, x) {
			if (d[0][i] == 0) dp[0][i] = 1;
		}
		rep(i, 0, y) {
			rep(j, 0, x) {
				if (d[i][j] == 1) continue;
				if (d[i][j] == 2 && d[i + 2][j] != 1) {
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				rep(k, -1, 2) {
					if (0 <= j + k&& j + k < x && d[i + 1][j + k] == 0) {
						dp[i + 1][j + k] += dp[i][j];
					}
				}
				if (d[i + 1][j] == 2) {
					dp[i + 1][j] += dp[i][j];
				}
			}
		}
		/*cout << endl;
		rep(i, 0, y + 2) {
			rep(j, 0, x) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		int ans = 0;
		rep(i, 0, x) {
			ans += dp[y - 1][i];
			if (d[y - 2][i] == 2) {
				ans += dp[y - 2][i];
			}
		}
		cout << ans << endl;
	}
}