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> 
#define N 15
using namespace std;
void func(int,int);
int jump(int,int);
int X,Y,data[N][N],memo[N+2][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<Y;i++)
      for(int j=0;j<X;j++)
	cin >> data[i][j];
    for(int i=0;i<Y+2;i++)
      for(int j=0;j<X;j++)
	memo[i][j]=0;
    for(int i=0;i<X;i++)
      if(data[0][i]!=1)
	func(0,i);
    int cnt=0;
    for(int i=0;i<X;i++)
      cnt+=memo[0][i];
    cout << cnt << endl;
  }
  return 0;
}
void func(int y,int x){
  if(y>=Y-1){
    memo[Y][x]=memo[Y-1][x]=1;
    return ;
  }
  if(0<=x-1&&data[y+1][x-1]==0){
    if(memo[y+1][x-1]!=0) memo[y][x]+=memo[y+1][x-1];
    else{
      func(y+1,x-1),memo[y][x]+=memo[y+1][x-1];
    }
  }
  if(x+1<X&&data[y+1][x+1]==0){
    if(memo[y+1][x+1]!=0) memo[y][x]+=memo[y+1][x+1];
    else{
      func(y+1,x+1),memo[y][x]+=memo[y+1][x+1];
    }
  }
  if(data[y+1][x]==0){
    if(memo[y+1][x]!=0) memo[y][x]+=memo[y+1][x];
    else{
      func(y+1,x),memo[y][x]+=memo[y+1][x];
    }
  }
  if(data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r==-2) memo[y][x]+=1,memo[y+1][x]=1;
    else if(r!=-1){
      if(memo[r][x]!=0) memo[y][x]+=memo[r][x];
      else{
	func(r,x),memo[y][x]+=memo[r][x];
      }
    }
  }
  if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  y+=2;
  while(1){
    if(y>=Y-1) return -2;
    if(data[y][x]==1) break;
    if(data[y][x]==0) return y;
    if(data[y][x]==2) y+=2;
  }
  return -1;
}

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) {
    fill(grid[0], grid[0]+400, 0);
    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-1) 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
	      && !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 << endl;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
int X,Y;
int fld[15][15];
long long dp[15][15];
int main() {
	while(cin>>X>>Y&&X&&Y){
		for(int i=0;i<Y;i++)for(int j=0;j<X;j++)cin>>fld[j][i];
		long long ans=0;
		for(int i=0;i<X;i++)for(int j=0;j<Y;j++)dp[i][j]=0;
		for(int i=0;i<X;i++)if(fld[i][Y-1]!=1)dp[i][Y-1]=1;
		for(int y=Y-2;y>=0;y--){
			for(int x=0;x<X;x++){
				if(fld[x][y]==0){
					for(int k=-1;k<=1;k++){
						int nx=x+k;
						if(nx<0||nx>=X)continue;
						if(nx==x&&fld[nx][y+1]!=1)dp[x][y]+=dp[nx][y+1];
						else if(fld[nx][y+1]==0)dp[x][y]+=dp[nx][y+1];
					}
				}else if(fld[x][y]==2){
					if(y+2>=Y)dp[x][y]=1;
					else dp[x][y]=dp[x][y+2];
				}
				if(y==0)ans+=dp[x][y];
			}
		}
		cout<<ans<<endl;
	}
}

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

const int MAX_SIZE = 15;
char field[MAX_SIZE+1][MAX_SIZE+3];
int dp[MAX_SIZE+1][MAX_SIZE+3];
int w, h;

bool judge(int i, int j){
	if(j > 0 && j <= w && field[j][i] == '0' && j <= h)
		return true;
	return false;
}

int main(){
	while(cin >> w >> h){
		if(w == 0 && h == 0) break;
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++)
				cin >> field[j][i];
		}
		int pattern = 0;
		for(int i = 0; i < MAX_SIZE+1; i++){
			for(int j = 0; j < MAX_SIZE+3; j++){
				dp[i][j] = 0;
			}
		}
		for(int i = 1; i <= w; i++){
			dp[i][1] = 1;
		}
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				if(field[j][i] == '2')
					dp[j][i+2] += dp[j][i];
				if(field[j][i] == '0'){
					dp[j][i+1] += dp[j][i];
					if(judge(i+1, j-1)) dp[j-1][i+1] += dp[j][i];
					if(judge(i+1, j+1)) dp[j+1][i+1] += dp[j][i];
				}
			}
		}
		int count = 0;
		for(int i = h+1; i <= h+2; i++){
			for(int j = 1; j <= w; j++){
				count += dp[j][i];
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

using namespace std;

int X, Y;
int field[15 + 2][15 + 2];
int dp[15 + 2][15 + 2];

void solve() {
	for (int i = 1; i <= X; i++) {
		if (field[0][i] == 0) {
			dp[0][i] = 1;
		}
	}
	for (int y = 0; y < Y; y++) {
		for (int x = 1; x <= X; x++) {
			if (field[y][x] == 2) {
				if (field[y + 2][x] != 1) {
					dp[y + 2][x] += dp[y][x];
				}
			} else if (field[y][x] == 0) {
				if (field[y + 1][x - 1] == 0) {
					dp[y + 1][x - 1] += dp[y][x];
				}
				if (field[y + 1][x] != 1) {
					dp[y + 1][x] += dp[y][x];
				}
				if (field[y + 1][x + 1] == 0) {
					dp[y + 1][x + 1] += dp[y][x];
				}
			}
		}
	}
	int sum = 0;
	for (int y = Y; y <= Y + 1; y++) {
		for (int x = 1; x <= X; x++) {
			sum += dp[y][x];
		}
	}
	printf("%d\n", sum);
}

int main() {
	while (scanf("%d %d ", &X, &Y) == 2) {
		if (X == 0 && Y == 0) {return 0;}

		fill(dp[0], &dp[15 + 2 - 1][15 + 2], 0);
		fill(field[0], &field[15 + 2 - 1][15 + 2], 1);
		for (int y = Y; y <= Y + 1; y++) {
			for (int x = 1; x <= X; x++) {
				field[y][x] = 2;
			}
		}
		for (int i = 0; i < Y; i++) {
			for (int j = 1; j <= X; j++) {
				scanf("%d ", &field[i][j]);
			}
		}
		/*
		for (int i = 0; i < Y + 2; i++) {
			for (int j = 0; j < X + 2; j++) {
				printf("%d ", field[i][j]);
			}
			printf("\n");
		}
		*/
		solve();
		/*
		for (int i = 0; i < Y + 2; i++) {
			for (int j = 0; j < X + 2; j++) {
				printf("%2d ", dp[i][j]);
			}
			printf("\n");
		}
		*/
	}
}