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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vvi field(h+1,vi(w));
		rep(i,h) rep(j,w)
			cin>>field[i][j];
		
		vvi dp(h+1,vi(w));
		rep(i,w)
			if(field[0][i]!=1)
				dp[0][i]=1;
		rep(i,h-1){
			rep(j,w){
				if(field[i][j]==1){
					dp[i][j]=0;
					continue;
				}
				if(field[i][j]==2){
					dp[i+2][j]+=dp[i][j];
					continue;
				}
				if(field[i+1][j]==2)
					dp[i+1][j]+=dp[i][j];
				for(int k=-1;k<=1;k++)
					if(0<=j+k && j+k<w && field[i+1][j+k]==0)
						dp[i+1][j+k]+=dp[i][j];
			}
		}
		ll res=0;
		repi(i,h-1,h+1) rep(j,w)
			if(field[i][j]!='1')
				res+=dp[i][j];
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
int X,Y;
int dp[20][20];
char maps[20][20];
int bun(int x,int y);
int dx[3]={-1,0,1};
main(){
  while(1){
    cin>>X>>Y;
    if(X==0&&Y==0){
      break;
    }
    for(int i=1;i<=Y;i++){
      for(int j=1;j<=X;j++){
	cin>>maps[i][j];
	dp[i][j]=0;
      }
    }
    int ans=0;
    for(int i=1;i<=X;i++){
      if(maps[1][i]!='1'){
	ans+=bun(1,i);
      }
    }
    cout<<ans<<endl;
  }
}
int bun(int y,int x){
  if(y>=Y+1){
    return 1;
  }
  else if(dp[y][x]!=0){
    return dp[y][x];
  }
  else if(maps[y][x]=='2'&&(y+2>=Y+1||maps[y+2][x]!='1')){
    return bun(y+2,x);
  }
  else if(maps[y][x]=='1'){
    return 0;
  }
  else{
    int anss=0;
    for(int i=0;i<3;i++){
      int nx=x+dx[i];
      if(i!=1){
	if(nx>0&&nx<=X&&maps[y+1][nx]=='0'){
	  anss+=bun(y+1,nx);
	}
      }
      else{
	if(maps[y+1][nx]!='1'){
	  anss+=bun(y+1,nx);
	}
      }
    }
    return dp[y][x]=anss;
  }	  	  
}

C++: #include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int dx[]={-1,0,1};
int main(){
	int X,Y,c[15][15],land[15][15],ans;
	while(cin>>X>>Y,X){
		rep(i,Y)rep(j,X)cin>>land[i][j],c[i][j]=i==0&&land[i][j]!=1;
		rep(i,Y-1)rep(j,X)if(land[i+1][j]!=1){
			if(land[i+1][j]==2)c[i+1][j]+=c[i][j];
			else rep(d,3)if(ck(j+dx[d],X)&&land[i][j+dx[d]]==0)
			c[i+1][j]+=c[i][j+dx[d]];
			if(i>0&&land[i-1][j]==2)c[i+1][j]+=c[i-1][j];
		}
		ans=0;
		rep(i,X){
			ans+=c[Y-1][i];
			if(Y>1&&land[Y-2][i]==2)ans+=c[Y-2][i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;
int main(){
  int x, y, course[50][50], route[52][52], i, j, sum;
  while(cin >> x >> y, x+y){
    sum = 0;
    for(i=0; i<52; i++){
      for(j=0; j<52; j++){
        route[i][j] = 0;
      }
    }
    for(i=0; i<y; i++){
      for(j=0; j<x; j++){
	cin >> course[i][j];
      }
    }
    for(i=0; i<y; i++){
      for(j=0; j<x; j++){
        if(i==0){
	  if(course[i][j]==0){
            route[i][j] = 1;
          }else{
            route[i][j] = 0;
          }
        }else{
          if(j==0){
            if(course[i][j]==0){
              if(course[i-1][j]==0){
	        route[i][j] += route[i-1][j];
              }
              if(course[i-1][j+1]==0){
                route[i][j] += route[i-1][j+1];
              }
            }else if(course[i][j]==1){
	      route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] = route[i-1][j];
                route[i+2][j] += route[i][j];
              }
            }
          }else if(j==x-1){
            if(course[i][j]==0){
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              if(course[i-1][j-1]==0){
                route[i][j] += route[i-1][j-1];
              }
            }else if(course[i][j]==1){
              route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] = route[i-1][j];
                route[i+2][j] += route[i][j];
              }
            }
          }else{
            if(course[i][j]==0){
              if(course[i-1][j]==0){
                route[i][j] += route[i-1][j];
              }
              if(course[i-1][j-1]==0){
                route[i][j] += route[i-1][j-1];
              }
              if(course[i-1][j+1]==0){
                route[i][j] += route[i-1][j+1];
              }
            }else if(course[i][j]==1){
              route[i][j] = 0;
            }else{
              if(course[i-1][j]==0){
                route[i][j] = route[i-1][j];
                route[i+2][j] += route[i][j];
              }
              if(course[i-2][j]==2){
                route[i][j] = route[i-2][j];
                route[i+2][j] += route[i][j];
              }
            }
          }
        }
      }
    }
    for(i=y-1; i<y+2; i++){
      for(j=0; j<x; j++){
        sum+=route[i][j];
      }
    }
    cout << sum << endl;
  }
  return 0;
}