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 "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-1; ++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 w,h;
int s[40][40];
int dp[40][40];
int dx[]={-1,0,1};
int ret(int y,int x){
	if(y>=h-1){
		if(h-1==y&&s[y][x]==1)
		return 0;
		return 1;
	}
	if(dp[y][x]!=-1)
	return dp[y][x];
	if(s[y][x]==1)
		return dp[y][x]=0;
	if(s[y][x]==2){
		return dp[y][x]=ret(y+2,x);
	}
	int ans=0;
	for(int i=0;i<3;i++){
		int nx=dx[i]+x;
		if(nx>=w||nx<0)
			continue;
		
		if(s[y+1][nx]==0){
			ans+=ret(y+1,nx);
		}else if(s[y+1][nx]==2){
			if(i!=1)
				continue;
			ans+=ret(y+1,nx);
		}
	}
	return dp[y][x]=ans;
}
int main(){
	while(cin>>w>>h,w||h){
		memset(dp,-1,sizeof(dp));
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
		cin>>s[i][j];
		int ans=0;
		for(int i=0;i<w;i++){
			//if(s[0][i]==0)
				ans+=ret(0,i);
		}
		cout<<dp[3][0]<<endl;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[20][20],f,j,i,k;
	long long int g,h[20][20];
	while(1){
		scanf("%d %d",&a,&s);
		if(a==0&&s==0) break;
		for(i=0;i<s;i++) h[0][i]=1;
		for(i=0;i<a;i++){
			for(j=0;j<s;j++) scanf("%d",&d[i][j]);
		}
		for(i=0;i<s;i++){
			if(d[0][i]==1) h[0][i]=0;
		}
		for(i=1;i<a;i++){
			for(j=0;j<s;j++) h[i][j]=0;
		}
		for(i=0;i<a-1;i++){
			for(j=0;j<s;j++){
				if(i!=0&&d[i][j]==2){
					if(i+2<a){
						if(d[i+2][j]!=1) h[i+2][j]+=h[i][j];
					}
					else h[i+1][j]+=h[i][j];
				}
				if(d[i][j]==0){
					if(j!=0) if(d[i+1][j-1]==0) h[i+1][j-1]+=h[i][j];
					if(j!=s){
						if(d[i+1][j+1]==0) h[i+1][j+1]+=h[i][j];
						if(d[i+1][j]==0||d[i+1][j]==2) h[i+1][j]+=h[i][j];
					}
				}
			}
		}
		g=0;
		for(j=0;j<s;j++) g+=h[a-1][j];
		/*printf("\n\n");
		for(i=0;i<a;i++){
			for(j=0;j<s;j++) printf("%7d ",h[i][j]);
			printf("\n");
		}*/
		printf("%d\n",g);
	}
	return 0;
}

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) {
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				rep(k, -1, 2) {
					if (j + k < 0 || j + k >= x || d[i + 1][j + k] != 0) continue;
					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) {
			if (d[y - 1][i] == 0) {
				ans += dp[y - 1][i];
			}
			else if (d[y - 1][i] == 2) {
				ans += dp[y - 1][i];
			}
			if (d[y - 2][i] == 2) {
				ans += dp[y - 2][i];
			}
		}
		cout << ans << endl;
	}
}

C++: #include <iostream>

using namespace std;

int X, Y, c[20][20], dp[20][20];
int dx[3] = {-1, 0, 1};

int main()
{
  while (cin >> X >> Y && (X && Y)) {
    
    for (int i = 1; i <= Y; i++)
      for (int j = 1; j <= X; j++)
        cin >> c[i][j];
    
    for (int x = 1; x <= X; x++) {
      dp[Y + 1][x] = dp[Y + 2][x] = 1;
      if (c[Y][x] == 1) {
        dp[Y][x] = 0;
      } else {
        dp[Y][x] = 1;
      }
    }
    
    for (int y = Y - 1; y >= 1; y--) {
      for (int x = 1; x <= X; x++) {
        dp[y][x] = 0;
        if (c[y][x] == 2) {
          dp[y][x] += dp[y + 2][x];
        } else if (c[y][x] == 0) {
          for (int k = 0; k < 3; k++) {
            int nx = x + dx[k];
            if (nx >= 1 && nx <= X) {
              if (nx != x) {
                if (c[y + 1][nx] == 0) {
                  dp[y][x] += dp[y + 1][nx];
                }
              } else {
                if (c[y + 1][nx] != 1) {
                  dp[y][x] += dp[y + 1][nx];
                }
              }
            }
          }
        }
      }
    }
    
    int res = 0;
    for (int x = 1; x <= X; x++) 
      res += dp[1][x];

    cout << res << endl;
  }
}