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<cstring>

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

int main()
{
	while( std::cin >> X >> Y, X | Y )
	{
		memset( field, -1, sizeof( field ) );
		memset( dp, 0, sizeof( dp ) );

		for( int i = 0; i != Y; ++i )
			for( int j = 0; j != X; ++j )
				std::cin >> field[i][j];

		for( int i = 0; i != X; ++i )
			if( field[0][i] != 1 )
				dp[0][i] = 1;
		
		for( int i = 1; i != Y; ++i )
		{
			for( int j = 0; j != X; ++j )
			{
				if( i < Y && field[i][j] != 1 )
				{
					for( int k = -1; k <= 1; ++k )
					{	
						if( field[i][j] == 2 && k )
							continue;

						if( j + k >= 0 && j + k < X && !field[i-1][j+k] )
							dp[i][j] += dp[i-1][j+k];
					}
				}

				if( i - 2 >= 0 && field[i][j] != 1 && field[i-2][j] == 2 )
					dp[i][j] += dp[i-2][j];
			}
		}

		
		int ans = 0;
		for( int j = 0; j != X; ++j )
		{
			ans += dp[Y-1][j];

			if( Y >= 2 && field[Y-2][j] == 2 )
				ans += dp[Y-2][j];
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

using namespace std;
int X,Y,imap[20][20];
const int dx[3] = {-1,0,1};
const int dy[3] = {1,1,1};
int sam,dp[20][20];

int solve(){
  
  int ans = 0;
  for(int i=0;i<=Y;i++)for(int j=0;j<=X;j++)dp[i][j] = (i==0 && imap[i][j] != 1)?1:0; 

  for(int i=0;i<Y-1;i++){
    for(int j=0;j<X;j++){
      if(dp[i][j] == 0)continue;
      if(imap[i][j] == 0){
	for(int k=0;k<3;k++){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(0<= nx && nx<X && 0<= ny && ny < Y && imap[ny][nx] != 1){
	      if((k == 0 || k == 2) && imap[ny][nx] == 2)continue;
	      dp[ny][nx]+=dp[i][j];
	  }
	}
      }
      else if(imap[i][j] == 2){
	if(i+2 <Y){
	  dp[i+2][j]+=dp[i][j];
	}
	else{
	  dp[Y-1][j]+=dp[i][j];
	}
      }
    }
  }
    
    for(int i=0;i<X;i++)ans += dp[Y-1][i];
    return ans;
}



bool Init(){
  cin >> X >> Y;
  if(X+Y == 0)return false;
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++){
      cin >> imap[i][j];
    }
  }
  sam = 0;
  return true;
}

int main(){
  while(true){
    if(!Init())break;
    cout << solve() << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int W, H;
int C[20][20];
long long dp[20][20];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;
    rep(i, H) rep(j, W) cin >> C[j][i];

    rep(x, W+1) rep(y, H+1) dp[x][y] = 0;
    rep(x, W) {
      if (C[x][0] == 1) continue;
      dp[x][0] = 1;
    }
    long long s = 0;
    rep(y, H) {
      rep(x, W) {
        for (int d=-1; d<=1; d++) {
          int nx = x+d, ny = y+1;
          if (C[x][y] == 2) {
            if (d != 0) continue;
            ny = y+2;
          }
          if (nx < 0 || nx >= W || C[nx][ny] == 1) continue;
          if (C[nx][ny] == 2 && d != 0) continue;

          if (ny >= H) {
            if (d == 0) s += dp[x][y];
          }
          else dp[nx][ny] += dp[x][y];
        }
      }
    }
    cout << s << "\n";
  }
  return 0;
}

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][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],memo[i][j]=0;
    for(int i=0;i<X;i++)
      if(data[0][i]==0) func(0,i);
    cout << endl;
    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++){
	cout << memo[i][j] << ' ';
      }
      cout << endl;
    }
    cout << endl;
    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-1][x]=1;
    return ;
  }
  if(y+1<Y&&0<=x-1&&data[y+1][x-1]==0){
    if(memo[y+1][x-1]==0) func(y+1,x-1);
    memo[y][x]+=memo[y+1][x-1];
  }
  if(y+1<Y&&x+1<X&&data[y+1][x+1]==0){
    if(memo[y+1][x+1]==0) func(y+1,x+1);
    memo[y][x]+=memo[y+1][x+1];
  }
  if(y+1<Y&&data[y+1][x]==0){
    if(memo[y+1][x]==0) func(y+1,x);
    memo[y][x]+=memo[y+1][x];
  }
  if(y+1<Y&&data[y+1][x]==2){
    int r=jump(y+1,x);
    if(r==-2) memo[y][x]+=1;
    else if(r!=-1){
      func(r,x);
      memo[y][x]+=memo[r][x];
    }
  }
  //if(memo[y][x]==0) data[y][x]=1;
}
int jump(int y,int x){
  while(1){
    y+=2;
    if(data[y][x]==1) break;
    if(y>=Y-1) return -2;
    if(data[y][x]==0) return y;
  }
  return -1;
}

C++: // AOJ 0203
#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
	int x, y;
	while (cin >> x >> y, x || y){
		int field[32][32];
		swap(x, y);
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		int dp[32][32];
		memset(dp, 0, sizeof(dp));

		for (int j = 1; j <= x; j++){
			if (field[1][j] == 0){
				dp[1][j] = 1;
			}
		}
		for (int i = 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (field[i][j] == 1){
					continue;
				}
				if (field[i][j] == 2){
					dp[i + 2][j] += dp[i][j];
					continue;
				}
				if (field[i + 1][j - 1] == 0){
					dp[i + 1][j - 1] += dp[i][j];
				}
				if (field[i + 1][j] != 1){
					dp[i + 1][j] += dp[i][j];
				}
				if (field[i + 1][j + 1] == 0){
					dp[i + 1][j + 1] += dp[i][j];
				}
			}
		}

		int ret = 0;
		for (int i = y - 1; i <= y; i++){
			for (int j = 1; j <= x; j++){
				if (i == y - 1){
					if (field[i][j] == 2) ret += dp[i][j];
					continue;
				}
				else {
					ret += dp[i][j];
				}
			}
		}
		cout << ret << endl;
	}

	return 0;
}