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 <algorithm>
#include <vector>
#include <cassert>
using namespace std;

int grid[30][30];

inline bool isAtObstacle(int x, int y) {
  return grid[y][x] == 1;
}

inline bool isAtSkiJump(int x, int y) {
  return grid[y][x] == 2;
}

int main() {
  int n, m;
  
  while(cin >> n >> m && n) {
    fill(grid[0], grid[0]+900, 0);
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	cin >> grid[i][j];
      }
    }
    
    long long dp[30][30][2] = {};
    
    for(int j=0; j<m; j++) {
      if(grid[0][j]==0) { dp[0][j][0] = 1; }
    }
    
    int extra = 0;
    for(int i=0; i<n-1; i++) {
      for(int j=0; j<m; j++) {
	
	// there is no case such that skier is at obstacle.
	if(isAtObstacle(j, i)) {
	  dp[i][j][0] = dp[i][j][1] = 0;
	  continue;
	}
	
	// A skier is at a ski jump.
	if(isAtSkiJump(j, i)) {
	  if(i+2 > n-1) extra += dp[i][j][0];
	  else {
	    if(isAtObstacle(j, i+2)) continue;
	    dp[i+2][j][0] += dp[i][j][0];
	  }
	}
	
	// skiing without jump.
	else {
	  // from the upper left
	  if( j-1 >= 0
	      && !isAtObstacle(j-1, i+1)
	      && !isAtSkiJump (j-1, i+1) ) {
	    dp[i+1][j-1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the above
	  if( !isAtObstacle(j, i+1) ) {
	    dp[i+1][j][0] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the upper right
	  if( j+1 < m
	      && !isAtObstacle(j+1, i+1)
	      && !isAtSkiJump (j+1, i+1) ) {
	    dp[i+1][j+1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	}
	
      }
    }
    
    int ans = 0;
    for(int i=0; i<m; i++) {
      ans += dp[n-1][i][0] + dp[n-1][i][1];
    }
    
    cout << ans + extra << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<cstring>
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 <bits/stdc++.h>

using namespace std;

int field[16][15];
int dp[16][15];

int n, m;

bool isIn(int x, int y){
    return 0 <= x && x < n && 0 <= y && y < m;
}

int main(){
    while(cin >> n >> m, n+m){
        for(int i=0; i < n; i++) for(int j=0; j< m; j++)cin >> field[i][j];
        for(int i=0; i < 16; i++) for(int j=0; j < 15; j++) dp[i][j] = 0;
        for(int i=0; i < m; i++) dp[0][i] = 1;
        for(int i=0; i < n; i++){
            for(int j=0; j < m; j++){
                if(field[i][j] == 0){
                    for(int k=-1; k <= 1; k++){
                        if(isIn(i+1, j+k) && !(k != 0 && field[i+1][j+k] == 2)){
                            dp[i+1][j+k] += dp[i][j];
                        }
                    }
                }
                else if(field[i][j] == 1) dp[i][j] = 0;
                else if(field[i][j] == 2) dp[i+2][j] += dp[i][j];
            }
        }
        for(int i=0; i< m; i++) if(field[n-1][i] != 1) dp[n][i] += dp[n-1][i];
        int count = 0;
        for(int i=0; i< m; i++) count += dp[n][i];
        cout << count << endl;
    }
}

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 >> x >> y;
		if (y + x == 0) break;
		int d[20][20];
		rep(i, 0, 20) rep(j, 0, 20) d[i][j] = 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] == 2 && d[i + 2][j] != 1) {
					dp[i + 2][j] += dp[i][j];
				}
				else if (d[i][j] == 0) {
					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;
	}
}

C++: #include<iostream>
#include<map>
#define pf p.first
#define ps p.second
using namespace std;
typedef pair<int,int>P;
int h,w,mas[20][20],memo[20][20],ans,tmp[]={-1,0,1};
int dfs(P);
int main(){
  while(cin >> w >> h && w||h){
    ans = 0;
    for(int i=0;i<20;i++) for(int j=0;j<20;j++) memo[i][j] = -1;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> mas[i][j];
    for(int i=0;i<w;i++) ans += dfs(P(0,i));
    cout << ans << endl;
  }
}
int dfs(P p){
  if(memo[pf][ps] != -1) return memo[pf][ps];
  if(mas[pf][ps] == 1) return 0;
  if(pf >= h - 1) return 1;
  if(mas[pf][ps] == 2) return (memo[pf][ps] = dfs(P(pf+2,ps)));
  else{
    int cnt = 0;
    for(int i=0;i<3;i++){
      int nx = pf + 1,ny = ps + tmp[i];
      if(ny>=0&&ny<w&&((mas[nx][ny]==0)||(mas[nx][ny]==2&&i==1))){
	  cnt += dfs(P(pf+1,ps+tmp[i]));
	}
    }
    return (memo[pf][ps] = cnt);
  }
}