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<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second

int dat[30][30];
int dp[30][30];
int main(void){
	int x,y;
	for(;;){
		scanf("%d%d",&x,&y);
		if(x==0)break;
		rep(j,y)rep(i,x){
			scanf("%d",&dat[i][j]);
		}
		memset(dp,0,sizeof(dp));
		memset(dat,0,sizeof(dat));
		rep(i,x)if(dat[i][0]==0)dp[i][0]=1;
		rep(j,y)rep(i,x){
			if(dat[i][j]==1)continue;
			if(dat[i][j]==2){
				if(dat[i][j+2]!=1)dp[i][j+2]+=dp[i][j];
				continue;
			}
			if(j!=y-1){
				if(i>0 && dat[i-1][j+1]==0){
					dp[i-1][j+1]+=dp[i][j];
				}
				if(i<x-1 && dat[i+1][j+1]==0){
					dp[i+1][j+1]+=dp[i][j];
				}
			}
			if(dat[i][j+1]!=1)dp[i][j+1]+=dp[i][j];
		}
		lli ans=0;
		/*
		printf("\n");
		rep(j,y){
			rep(i,x){
				//printf("(%2d %2d)",dat[i][j],dp[i][j]);
				printf("%2d",dp[i][j]);
			}
			printf("\n");
		}*/
		reg(j,y,y+1){
			//printf("\n");
			rep(i,x){
				//printf("%2d ",dp[i][j]);
				ans+=dp[i][j];
			}
		}
		printf("%lld\n",ans);
	}
	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+2][N];
int main(){
  while(1){
    cin >> X >> Y;
    if(X==0&&Y==0) break;
    for(int i=0;i<N+2;i++){
      for(int j=0;j<N+2;j++){
	data[i][j]=0;
      }
    }
    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(y+1<Y&&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(y+1<Y&&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!=-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(data[y][x]==1) break;
    if(data[y][x]==0) return y;
    if(y>=Y-1) return y;
    y+=2;
  }
  return -1;
}

C++: #include<iostream>
using namespace std;
typedef long long int ll;
//typedef int ll;
ll w,h,xd[]={1,0,-1},p,u[20][20],d[20][20];
ll ret(ll x,ll y){
	ll s=x,sum=0;
	if(h-1<=y){
		return 1;
	}
	if(d[y][x]>=1)
		return d[y][x];
	else if(u[y][x]==2)
		return d[y][x]=ret(x,y+2);
	else if(u[y][x]==0){
		y++;
		for(ll i=0;i<3;i++){
			x=s+xd[i];
			if(x>=0&&x<=w-1){
    			if(u[y][x]==2&&i==1)
 	     			sum+=d[y-1][s]=ret(x,y+2);
				else if(u[y][x]==0)
					sum+=d[y-1][s]=ret(x,y);
			}
		}
		return d[y-1][s]=sum;
	}
	return d[y][s]=-1;
}
int main(){
	ll x,y;
	while(cin>>w>>h,w||h){
		p=0;
		for(ll i=0;i<h;i++)
		for(ll j=0;j<w;j++){
			cin>>u[i][j];
			d[i][j]=0;
		}
		for(ll i=0;i<w;i++)
			u[h][i]=0;
		for(ll i=0;i<w;i++){
			if(u[0][i]==0){
				x=i;
				y=0;
				p+=ret(x,y);
			}
			else if(u[0][i]==2){
				x=i;
				y=2;
				p+=ret(x,y);
			}
		}
		cout<<p<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void){
	int x,y,i,j;
	while(scanf("%d%d",&x,&y),x,y){
		int masu[20][20]={ 0 };
		int dp[20][20]={0};
		int ans=0;
		for(i=1;i<=y;i++){
			for(j=1;j<=x;j++){
				scanf("%d",&masu[i][j]);
			}
		}
		for(j=1;j<=x;j++){
			if(masu[1][j]==0)dp[1][j]=1;
		}
		for(i=2;i<=y;i++){
			for(j=1;j<=x;j++){
				if(masu[i][j]==0){
					if(masu[i-1][j-1]!=2)dp[i][j]+=dp[i-1][j-1];
					if(masu[i-1][j]!=2)	 dp[i][j]+=dp[i-1][j];
					if(masu[i-1][j+1]!=2)dp[i][j]+=dp[i-1][j+1];
					if(masu[i-2][j]==2){
						dp[i][j]+=dp[i-2][j];
					}
				}
				if(masu[i][j]==1){
					dp[i][j]=0;
				}
				if(masu[i][j]==2){
					dp[i][j]=dp[i-1][j];
					if(masu[i-2][j]==2)dp[i][j]+=dp[i-2][j];
				}
			}
		}
		for(i=1;i<=x;i++){
			ans+=dp[y][i];
			if(masu[y-1][i]==2)ans+=dp[y-1][i];
		}
		
		printf("%d\n",ans);
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int x, y;
	while (scanf("%d %d", &x, &y), x | y)
	{
		int topo[15 + 1][15 + 2];
		memset(topo, 0, sizeof(topo));
		for (int i = 0; i < y; ++i)
			for (int j = 1; j <= x; ++j)
				scanf("%d", &topo[i][j]);

		int dp[15 + 1][15 + 2];
		memset(dp, 0, sizeof(dp));
		for (int i = 1; i <= x; ++i)
			if (topo[0][i] != 1)
				dp[0][i] = 1;

		for (int i = 0; i < y-1; ++i)
		{
			for (int j = 1; j <= x; ++j)
			{
				if (topo[i][j] == 0)
				{
					for (int k = -1; k <= 1; ++k)
						if (topo[i+1][j+k] != 1 && (topo[i+1][j+k] == 0 || k == 0))
							dp[i+1][j+k] += dp[i][j];
				}
				else if (topo[i][j] == 2 && topo[i+2][j] != 1)
					dp[i+2][j] += dp[i][j];
			}
		}
		int ans = 0;
		for (int i = 1; i <= x; ++i)
			ans += dp[y-1][i] + dp[y][i];
		printf("%d\n", ans);
	}

	return 0;
}