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[20][20];

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) {
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	cin >> grid[i][j];
      }
    }
    
    long long dp[20][20][2] = {};
    
    for(int j=0; j<m; j++) {
      if(grid[0][j]==0) { dp[0][j][0] = 1; }
    }
    
    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)) continue;
	
	// A skier is at a ski jump.
	if(isAtSkiJump(j, i)) {
	  if(i+2>=n) dp[n-1][j][0] += dp[i][j][0];
	  else dp[i+2][j][0] += dp[i][j][0];
	}
	// skiing without jump.
	else {
	  // from the upper left
	  if(j-1>=0) {
	    if(   !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) {
	    if(   !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 << endl;
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){

    int w,h;
    while(cin>>w>>h){
        int data[16][16]={{0}},dp[17][17]={{0}};
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>data[i][j];
                if(i==0&&data[i][j]!=1)dp[i][j]=1;
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(dp[i][j]!=0){
                    if(data[i][j]==0){
                        if(j!=0&&data[i+1][j-1]==0)dp[i+1][j-1]+=dp[i][j];
                        if(data[i+1][j]!=1)dp[i+1][j]+=dp[i][j];
                        if(j!=w-1&&data[i+1][j+1]==0)dp[i+1][j+1]+=dp[i][j];
                    }
                    else if(data[i][j]==2){
                        if(i+2>=h)dp[i+1][j]+=dp[i][j];
                        if(data[i+2][j]!=1)dp[i+2][j]+=dp[i][j];
                    }
                }
            }
        }
        int ans=0;
        for(int j=0;j<w;j++)ans+=dp[h-1][j];
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

int main(){
	int n,m;
	int masu[17][17];
	int ura[17][17];
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0){
			break;
		}
		for(int i=0;i<17;i++){
			for(int j=0;j<17;j++){
				masu[i][j]=0;
				ura[i][j]=0;
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				scanf("%d",&ura[i][j]);
			}
		}
		for(int i=1;i<=n;i++){
			switch(ura[1][i]){
				case 0:masu[1][i]+=1;break;
				case 1:masu[1][i]+=0;break;
				case 2:masu[1][i]+=1;break;
			}
		}
		for(int i=1;i<n;i++){
			for(int j=1;j<=m;j++){
				if(ura[i][j]==0){
					if(ura[i+1][j-1]==0){
						masu[i+1][j-1]+=masu[i][j];
					}
					if(ura[i+1][j]!=1){
						masu[i+1][j]+=masu[i][j];
					}
					if(ura[i+1][j+1]==0){
						masu[i+1][j+1]+=masu[i][j];
					}
				}else if(ura[i][j]==2){
					if(ura[i+2][j]!=1){
						masu[i+2][j]+=masu[i][j];
					}
				}
			}
		}
		
		int cont=0;
		for(int i=n;i<=n+1;i++){
			for(int j=1;j<=m;j++){
				cont+=masu[i][j];
			}
		}
		printf("%d\n",cont);
	}
	
}

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

int dfs(int x,int y);
int mas[20][20];
int memo[20][20];
int X,Y;

int main(){
	while(1){
		cin >> X >> Y;
		if(X == 0 && Y == 0) break;
		for(int i=0;i<20;i++){
			for(int j=0;j<20;j++){
				memo[i][j] = -1;
			}
		}
		for(int i=0;i<Y;i++){
			for(int j=0;j<X;j++){
				cin >> mas[i][j];
			}
		}
		int ans = 0;
		for(int i=0;i<X;i++){
			if(mas[0][i] == 0){
				ans += dfs(i,0);
			}
		}
		cout << ans << endl;
	}
}

int dfs(int x,int y){
	if(memo[y][x] != -1) return memo[y][x];
	if(mas[y][x] == 1) return 0;
	if(y>=Y-1) return 1;
	if(mas[y][x] == 2) return (memo[y][x] = dfs(x,y+2));
	else{
		int cou = 0;
		for(int i=-1;i<2;i++){
			int nx = x + i;
			int ny = y + 1;
			if(nx >= 0 && nx < X && ((i == 0 && mas[ny][nx] == 2) || (mas[ny][nx] == 0))){
				cou += dfs(nx,ny);
			}
		}
		return (memo[y][x] = cou);
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            return 0;

        vector<vector<int> > grid(h+1, vector<int>(w+2, 0));
        for(int i=0; i<h+1; ++i)
            grid[i][0] = grid[i][w+1] = 1;
        for(int i=0; i<h; ++i){
            for(int j=1; j<=w; ++j){
                cin >> grid[i][j];
            }
        }

        vector<vector<int> > num(h+1, vector<int>(w+2, 0));
        for(int i=1; i<=w; ++i){
            if(grid[0][i] == 0)
                num[0][i] = 1;
        }

        for(int y=0; y<h-1; ++y){
            for(int x=1; x<=w; ++x){
                if(grid[y][x] == 2){
                    if(grid[y+2][x] != 1)
                        num[y+2][x] += num[y][x];
                }else{
                    for(int dx=-1; dx<=1; ++dx){
                        if(grid[y+1][x+dx] == 1 || (grid[y+1][x+dx] == 2 && dx != 0))
                            continue;
                        num[y+1][x+dx] += num[y][x];
                    }
                }
            }
        }

        int ret = accumulate(num[h-1].begin(), num[h-1].end(), 0);
        ret += accumulate(num[h].begin(), num[h].end(), 0);
        cout << ret << endl;
    }
}