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[16][15];

int main()
{
	while( std::cin >> X >> Y, X | Y )
	{
		memset( field, 0, 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 )
			dp[0][i] = field[0][i] != 1;
		
		int ans = 0;
		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];

				if( i >= Y - 1 )
					ans += dp[i][j];
			}
		}

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

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int a[16][16];
int count = 0;
int n,m;

void dfs(int y,int x)
{
	if(y > m-1)
	{
		return;
	}

	if(a[y][x] == 0)
	{
		if(y == m-1)
		{
			count++;
			return;
		}
		if(x-1 >= 0 && y+1 < m)
		{
			if(a[y+1][x-1] != 2)
			{
				dfs(y+1,x-1);
			}
		}
		if(y+1 < m)
		{
			dfs(y+1,x);
		}
		if(x+1 < n && y+1 < m)
		{
			if(a[y+1][x+1] != 2)
			{
				dfs(y+1,x+1);
			}
		}
		return;
	}
	else if(a[y][x] == 1)
	{
		return;
	}
	else if(a[y][x] == 2)
	{
		if(y == m-2)
		{
			count++;
			return;
		}
		else if(y == m-1)
		{
			count++;
			return;
		}
		else
		{
			dfs(y+2,x);
		}
	}
}

int main()
{
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0)
		{
			break;
		}

		memset(a,0,sizeof(a));
		rep(i,n)
		{
			rep(j,m)
			{
				cin >> a[i][j];
			}
		}
		count = 0;
		rep(i,n) dfs(0,i);

		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream> 
#define N 16
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<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(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(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>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <numeric>
#include <algorithm>

using namespace std;

int main(int argc, char **argv) {
  int x, y, **field, **route, rsum;

  while (true) {
    cin >> x >> y;
    if (x == 0 && y == 0)
      break;
    rsum = 0;
    field = new int*[y];
    route = new int*[y];
    for (int i = 0; i < x; i++) {
      field[i] = new int[x];
      route[i] = new int[x];
      memset(route[i], 0, sizeof(int) * x);
    }
    for (int i = 0; i < y; i++)
      for (int j = 0; j < x; j++)
        cin >> field[i][j];
    for (int i = 0; i < x; i++) {
      int f = field[0][i];
      if (!f)
        route[0][i] = 1;
    }

    for (int i = 1; i < y; i++)
      for (int j = 0; j < x; j++) {
        int f = field[i][j];
        if (f == 0) {
          for (int k = -1; k <= 1; k++)
            if ((j + k >= 0 && j + k < x) &&
                ((k == 0 && field[i-1][j+k] == 2) ||
                 (field[i-1][j+k] != 2)))
              route[i][j] += route[i-1][j+k];
        } else if (f == 1) {
          route[i][j] = 0;
        } else if (i + 2 < y) {
          route[i+2][j] = route[i-1][j];
        } else if (i + 2 >= y) {
          rsum += route[i-1][j];
        }
      }
    for (int i = 0; i < x; i++)
      rsum += route[y-1][i];

    cout << rsum << endl;
    /* for DEBUG */
    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        cout << route[i][j];
        cout << ' ';
      }
      cout << endl;
    }

  }
  return 0;
}

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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int x, y, c[50][50], dp[50][50];
const int dx[3] = {-1, 0, 1};

void solve() {
  memset(dp, 0, sizeof dp);
  
  rep(i,y) rep(j,x) cin>>c[i][j];
  
  rep(i,x) if (c[0][i] == 0) dp[0][i] = 1;
  
  rep(i,y-1) rep(j,x) {
    if (c[i][j] == 0) {
      rep(z,3) {
        int ti = i + 1, tj = j + dx[z];
        if (tj < 0 || tj >= x) continue;
        if (c[ti][tj] == 1) continue;
        if (c[ti][tj] == 2 && z != 1) continue;
        dp[ti][tj] += dp[i][j];
      }
    } else if (c[i][j] == 2 && c[i+2][j] != 1) {
      dp[i+2][j] += dp[i][j];
    }
  }
  /*
  rep(i,y+1) {
    rep(j,x) printf("%8d",dp[i][j]);
    cout<<endl;
  }*/
  
  int res = 0;
  rep(j,x) res += dp[y][j] + dp[y-1][j];
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>x>>y, x||y) {
    solve();
  }
  return 0;
}