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>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int H, W;
int maps[15][15];
ll dp[15][15];

int dx[3] = {1,0,-1}, dy[3] = {1,1,1};

int main() {
	while (cin >> W >> H, H || W) {
		REP(i, H) REP(j, W) scanf("%d", &maps[i][j]);
		
		memset(dp, 0, sizeof(dp));
		REP(j, W) dp[0][j] = maps[0][j] != 1;
		
		REP(i, H) REP(j, W) if (dp[i][j]) {
			
			if (maps[i][j] == 2) { // jump
				if (i + 2 < H && maps[i + 2][j] == 1) continue;
				dp[min(i + 2, H - 1)][j] += dp[i][j];
			}
			else { // normal
				REP(k, 3) {
					int yy = i + dy[k], xx = j + dx[k];
					if (!(yy >= 0 && yy < H && xx >= 0 && xx < W)) continue;
					if (maps[yy][xx] == 1 || (k != 1 && maps[yy][xx] == 2)) continue;
					dp[yy][xx] += dp[i][j];
				}
			}
		}
		
		ll ans = 0;
		REP(j, W) ans += dp[H - 1][j];
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX = 17;
int in[MAX][MAX], X,Y,data[MAX][MAX],ans;
int dx[4] = {-1,0,1};


void init(){
  memset(data,0,sizeof(data));
  ans = 0;
}


void solve(){
  for(int i = 1; i <= Y; i++)
    for(int j = 1; j <= X; j++){
      for(int k = 0; k < 3; k++)
	if(in[i][j] == 0){
	  int f = j+dx[k];
	  if(i-1 > 0 && 0 < f && f <= X){
	    if(in[i-1][f] != 2) data[i][j] += data[i-1][f];
	    // if(i-2 > 0 && in[i-1][f] == 2) data[i][j] += data[i-2][f];
	  }

	}else if(in[i][j] == 2){
	  if(i-1 > 0) data[i][j] += data[i-1][j];
	  if(i+2 <= Y) data[i+2][j] += data[i][j];
	  break;
	}
	/*
	if(i-1 > 0 && j+dx[k] > 0 && j+dx[k] <= X && in[i][j] != 1 && in[i-1][j+dx[k]] != 2){
	  if(in[i][j] == 2) data[i][j] = data[i-1][j];
	  else data[i][j] += data[i-1][j+dx[k]];
	}
      if(i-2 > 0 && in[i-2][j] == 2 && in[i][j] != 1) data[i][j] += data[i-2][j];
	*/
    }

  for(int j = 1; j <= X; j++){
    if(Y-1 > 0 && in[Y-1][j] == 2) ans+=data[Y-1][j];
    ans+=data[Y][j];
  }
  cout << ans << endl;
}

void print(){
  for(int i = 1; i <= Y; i++){
    for(int j = 1; j <= X; j++)
      cout << data[i][j]<< " ";
    cout << endl;
  }
}
int main(){
  while(cin >> X >> Y && X+Y){
    init();
    for(int i = 1; i <= Y; i++)
      for(int j = 1; j <= X; j++)
	cin >> in[i][j];
    
    for(int i = 1; i <= X; i++)
      if(in[1][i] == 0) data[1][i] = 1;

    solve();
    //print();
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};

void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = dx[i]+x, ny = y+1;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;
      if(memo[ny][nx] > 0 && mp[ny][nx] == 0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0){
	saiki(nx,ny);
	memo[y][x] += memo[ny][nx];
      }
      else if(nx==x && mp[ny][nx] == 2){
	int ty = ny;
	while(mp[ty][nx] == 2) ty+=2;
	if(mp[ty][nx] == 0 && memo[ty][nx] == 0){
	  saiki(nx,ty);
	  memo[y][x] += memo[ty][nx];
	}
	else if(mp[ty][nx] == 0 && memo[ty][nx] > 0) memo[y][x] += memo[ty][nx];
      }
    }
    if(memo[y][x] == 0) mp[y][x] = 1;
  }
}
  
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
 
    for(int i=0;i<w;i++) 
      if(mp[0][i] !=1) saiki(i,0);
    
    int cnt = 0;
    for(int i=0;i<w;i++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

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

using namespace std;

int field[20][20];
long long dp[20][20];

int main()
{
  int c1, c2;
  while (scanf(" %d %d ", &c1, &c2) == 2) {
    if (c1 == 0 && c2 == 0) {break;}
    for (int i = 0; i < 20; i++) {
      fill(field[i], &field[i][20], 1);
      fill(dp[i], &dp[i][20], 0);
    }
    for (int i = 1; i <= c1; i++) {
      for (int j = 1; j <= c2; j++) {
	scanf(" %d ", &field[i][j]);
      }
    }
    /*for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
	printf("%d", field[i][j]);
      }
      printf("\n");
      }*/
    
    for (int i = 1; i <= c2; i++) {
      dp[1][i] = 1;
    }
    for (int i = 1; i < c1; i++) {
      for (int j = 1; j <= c2; j++) {
	if (field[i][j] == 0) {
	  if (field[i + 1][j - 1] != 2) {dp[i + 1][j - 1] += dp[i][j];}
	  dp[i + 1][j] += dp[i][j];
	  if (field[i + 1][j + 1] != 2) {dp[i + 1][j + 1] += dp[i][j];}
	} else if (field[i][j] == 2) {
	  dp[i + 2][j] += dp[i][j];
	} 
      }
    }
    long long sum = 0;
    for (int i = 0; i <= 2; i++) {
      for (int j = 1; j <= c2; j++) {
	if (i != 0 || field[c1 + i][j] != 1) {
	  sum += dp[c1 + i][j];
	}
      }
    }
    
    printf("%d\n", sum);
  }
}