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>

using namespace std;

#define MAX 20

int W,H;
int arr[MAX][MAX];
int dp[MAX][MAX];
const int dx[] = {-1,0,1};
const int dy[] = {1,1,1};

bool inField(int y,int x){
  return 0 <= y && y < H && 0 <= x && x < W;
}

int solve(int y,int x){
  if(y == H-1){
    if(arr[y][x] == 0 || arr[y][x] == 2){
      return 1;
    }else{
      return 0;
    }
  }
  if(dp[y][x] != -1) return dp[y][x];

  int res = 0;
  if(arr[y][x] != 2){
    for(int i = 0 ; i < 3 ; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(!inField(ny,nx)) continue;
      if(arr[ny][nx] == 1) continue;
      if(arr[ny][nx] == 0){
        res += solve(ny,nx);
      }else{
        if(x == nx){
          res += solve(ny,nx);
        }
      }
    }
  }else{
    int nx = x, ny = y + 2;
    if(!inField(ny,nx)) return 1;
    if(arr[ny][nx] == 1) return 0;
    res += solve(ny,nx);
  }
  return dp[y][x] = res;
}

int main(){
  while(cin >> W >> H, (W | H)){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> arr[i][j];
        dp[i][j] = -1;
      }
    }
    int res = 0;
    for(int i = 0 ; i < W ; i++){
      if(arr[0][i] == 0){
        res += solve(0,i);
      }
    }
    cout << res << endl;
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int solve(int x,int y);
int ax,ay;
int mas[20][20];
int memo[20][20];
int main(){
  while(1){
    int ans=0;
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++){
	memo[i][j]=0;
      }
    }
    cin>>ax>>ay;
    if(ax==0 && ay==0){
      break;
    }
    for(int i=0;i<ay;i++){
      for(int j=0;j<ax;j++){
	cin>>mas[i][j];
      }
    }
    for(int i=0;i<ax;i++){
      if(mas[0][i]!=1){
	ans+=solve(i,0);
      }
    }
    cout<<ans<<endl;
  }
}
int solve(int x,int y){
  if(memo[y][x]!=0){
    return memo[y][x];
  }
  else if(y==ay){
    return 1;
  }else if(mas[y][x]==1){
    return 0;
  }else if(mas[y][x]==2){
    return solve(x,y+2);
  } 
  else{
    int anss=0; 
    if(mas[y+1][x]!=1){
      anss+=solve(x,y+1);
    }
    if(x+1<ax && mas[y+1][x+1]==0 && y+1!=ay){
      anss+=solve(x+1,y+1);
    }
    if(0<=x-1 && mas[y+1][x-1]==0 && y+1!=ay){
      anss+=solve(x-1,y+1);
    }
    return memo[y][x]=anss;
  }
}

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

int main() {
	int s,i,j,x,y,c[15][15],d[17][15];
	while(cin >> x >> y) {
		if (x+y==0) break;
		for (i=0;i<y;i++) for (j=0;j<x;j++) cin >> c[i][j];
		for (i=0;i<y+2;i++) for (j=0;j<x;j++) d[i][j]=(i==0);
		for (i=0;i<y-1;i++) for (j=0;j<x;j++) {
			s=d[i][j];
			if (c[i][j]==0) { 
				if (j>0) if (c[i+1][j-1]==0) d[i+1][j-1]+=s;
				if (j<x-1) if (c[i+1][j+1]==0) d[i+1][j+1]+=s;
				if (c[i+1][j]!=1) d[i+1][j]+=s;
			}
			if (c[i][j]==2 && c[i+2][j]!=1) d[i+2][j]+=s;
		}
		s=0;
		for (i=y-1;i<=y;i++) for (j=0;j<x;j++) s+=d[i][j];
		if (y==1) { s=0; for (i=0;i<x;i++) s+=(c[0][i]==0);}
		cout << s << endl; 
	 }
	return 0;
}

C++: // ツ堕スツ閉ェDPツつキツづェツづ篠余ツ裕ツつセツつェツ・ツ・ツ・

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int X, Y;
int ba[15][15];
map<pair<int,int>, int> mp;

int const dx[] = {-1,0,1};
int solve(int x, int y) {
  if (y >= Y-1) return 1;
  if (mp[make_pair(x,y)])
    return mp[make_pair(x,y)];
  int res = 0;
  REP(i,3) {
    int xx = x + dx[i];
    int yy = y+1;
    
    if (xx < 0 || X <= xx) continue;
    if (i == 1) {
      while (yy < Y && ba[xx][yy] == 2) {
        yy+=2;
      }
      if (yy >= Y || ba[xx][yy] == 0)
        res += solve(xx, yy);
    } else if (ba[xx][yy] == 0) {
      res += solve(xx, yy);
    }
  }
  return mp[make_pair(x,y)] = res;
}

int main() {
  while(cin >> X >> Y, X||Y) {
    mp.clear();
    REP(y,Y) {
      REP(x,X) {
        cin >> ba[x][y];
      }
    }
    int ans = 0;
    REP(x,X) {
      ans += solve(x, 0);
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
using namespace std;
typedef pair<int,int> P;
const int INF = ~(1<<31) / 2;

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

int main(){
    while(1){
        int X,Y;
        scanf("%d %d",&X,&Y);
        if(X==0)break;
        for(int i=0;i<Y;i++){
            for(int j=0;j<X;j++){
                scanf("%d",&field[i][j]);
            }
        }

        for(int j=0;j<X;j++){
            dp[Y-1][j] = field[Y-1][j] == 1 ? 0 : 1;
        }

        for(int i=Y-2;i>=0;i--){
            for(int j=0;j<X;j++){
                if(field[i][j]==1){
                    dp[i][j] = 0;
                }else if(field[i][j]==2){
                    dp[i][j] = i+2<Y ? dp[i+2][j] : 1;
                }else{
                    dp[i][j] = 0;
                    if(j-1>=0 && field[i+1][j-1]==0){
                        dp[i][j] += dp[i+1][j-1];
                    }
                    if(j+1<X && field[i+1][j+1]==0){
                        dp[i][j] += dp[i+1][j+1];
                    }
                    if(field[i+1][j]!=1){
                        dp[i][j] += dp[i+1][j];
                    }
                }
            }
        }
        int ans = 0;
        for(int j=0;j<X;j++){
            ans += dp[0][j];
        }
        printf("%d\n",ans);
    }

    return 0;
}