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 <algorithm>
#include <vector>
#include <cassert>
using namespace std;

int grid[30][30];

inline bool isAtObstacle(int x, int y) {
  return grid[y][x] == 1;
}

inline bool isAtSkiJump(int x, int y) {
  return grid[y][x] == 2;
}

int main() {
  int n, m;
  
  while(cin >> n >> m && n) {
    fill(grid[0], grid[0]+900, 0);
    for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) {
	cin >> grid[i][j];
      }
    }
    
    long long dp[30][30][2] = {};
    
    for(int j=0; j<m; j++) {
      if(grid[0][j]==0) { dp[0][j][0] = 1; }
    }
    
    for(int i=0; i<n-1; i++) {
      for(int j=0; j<m; j++) {
	
	// there is no case such that skier is at obstacle.
	if(isAtObstacle(j, i)) {
	  dp[i][j][0] = dp[i][j][1] = 0;
	  continue;
	}
	
	// A skier is at a ski jump.
	if(isAtSkiJump(j, i)) {
	  if(i+2 > n-1) dp[n-1][j][0] += dp[i][j][0];
	  else {
	    if(isAtObstacle(j, i+2)) continue;
	    dp[i+2][j][0] += dp[i][j][0];
	  }
	}
	
	// skiing without jump.
	else {
	  // from the upper left
	  if( j-1 >= 0
	      && !isAtObstacle(j-1, i+1)
	      && !isAtSkiJump (j-1, i+1) ) {
	    dp[i+1][j-1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the above
	  if( !isAtObstacle(j, i+1) ) {
	    dp[i+1][j][0] += dp[i][j][0] + dp[i][j][1];
	  }
	  
	  // from the upper right
	  if( j+1 < m
	      && !isAtObstacle(j+1, i+1)
	      && !isAtSkiJump (j+1, i+1) ) {
	    dp[i+1][j+1][1] += dp[i][j][0] + dp[i][j][1];
	  }
	}
	
      }
    }
    
    int ans = 0;
    for(int i=0; i<m; i++) {
      ans += dp[n-1][i][0] + dp[n-1][i][1];
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class point {
public:
	int num;
	int block;
	point() :num(0), block(2) {}
};
int main() {
	int X, Y;
	while (cin >> X >> Y&&X != 0) {
		vector<vector<point> > map(X + 2, vector<point>(Y + 2));
		for (int y = 1; y <= Y; ++y) {
			for (int x = 1; x <= X; ++x) {
				cin >> map[x][y].block;
			}
		}
		for (int i = 1; i <= X; ++i) {
			if (map[i][1].block == 0) {
				map[i][1].num = 1;
			}
		}
		for (int y = 1; y <= Y; ++y) {
			for (int x = 1; x <= X; ++x) {
				if (map[x][y].block == 2) {
					int dy = min(Y + 1, y + 2);
					if (map[x][dy].block != 1) {
						map[x][dy].num += map[x][y].num;
					}
				}
				else if (map[x][y].block == 0) {
					for (int k = -1; k <= 1; ++k) {
						int dx = x + k;
						int dy = y + 1;
						if (map[dx][dy].block == 0) {
							map[dx][dy].num += map[x][y].num;
						}
						else if (map[dx][dy].block == 2 && k == 0) {
							map[dx][dy].num += map[x][y].num;
						}
					}
				}
			}
		}
		int ans = 0;
		for (int x = 1; x <= X; ++x) {
			ans += map[x][Y + 1].num;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int m[500][500];
int dp[500][500];

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

int solve(int r,int c){
  rep(i,r+2)rep(j,c)dp[i][j]=0;
  rep(j,c)if(m[0][j] == 2 || m[0][j] == 0)dp[0][j]=1;

  rep(i,r){
    rep(j,c){
      if (m[i][j] == 0 && i != r-1){
	rep(k,3){
	  int nex = j+dx[k];
	  if (nex<0||nex>=c)continue;
	  if (m[i+1][nex] == 0)dp[i+1][nex]+=dp[i][j];
	  else if (m[i+1][nex] == 2 && k == 1)dp[i+1][nex]+=dp[i][j];
	}
      }else if (m[i][j] == 2 ){
	dp[i+2][j]+=dp[i][j];
      }
    }
  }
  
  int ans = 0;
  rep(j,c)ans+=dp[r][j]+dp[r-1][j]+dp[r+1][j];
  return ans;
}

main(){
  int c,r;
  while(cin>>c>>r && r){
    rep(i,r)rep(j,c)cin>>m[i][j];
    rep(j,c)m[r][j]=m[r+1][j]=0;
    cout << solve(r,c) << endl;
  }
}

C++: #include <iostream>

using namespace std;

int C[15][15], dp[15][17];

int main() {
  for (;;) {
    int X, Y;
    cin >> X >> Y;
    if (!X && !Y) return 0;
    for (int y = 0; y < Y; y++)
      for (int x = 0; x < X+2; x++) {
        C[y][x] = 1;
        dp[y][x] = 0;
      }
    for (int y = 0; y < Y; y++)
      for (int x = 1; x <= X; x++)
        cin >> C[y][x];
    for (int x = 1; x <= X; x++)
      if (!C[0][x])
        dp[0][x] = 1;
    for (int y = 1; y < Y; y++)
      for (int x = 1; x <= X; x++) {
        switch (C[y][x]) {
        case 1:
          break;
        case 0:
          dp[y][x] += (C[y-1][x-1] ? 0 : dp[y-1][x-1]) +
                      (C[y-1][x+1] ? 0 : dp[y-1][x+1]);
        case 2:
          if (y >= 2 && C[y-2][x] == 2)
            dp[y][x] += dp[y-2][x];
          dp[y][x] += C[y-1][x] ? 0 : dp[y-1][x];
          break;
        default:
          break;
        }
      }
    int s = 0;
    for (int x = 1; x <= X; x++)
      s += dp[Y-1][x];
    if (Y >= 2)
      for (int x = 1; x <= X; x++)
        if (C[Y-2][x] == 2)
          s += dp[Y-2][x];
    cout << s << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

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


int main(){
	while(true){
		int maxX,maxY;
		cin >> maxX >> maxY;			if(!maxX&&!maxY) return 0;

		int tizu[maxX+2][maxY+2];
		FOR(y,0,maxY+2){
			FOR(x,0,maxX+2){
				if(x==0||x==maxX+1||y==0||y==maxY+1){tizu[x][y]=1;continue;};
				cin >> tizu[x][y];
			}
		}

		int dp[maxX+2][maxY+2];
		FOR(y,0,maxY+2){
			FOR(x,0,maxY+2){
				dp[x][y]=0;
				if(x==0||x==maxX+1){
					continue;
				}
				if(y==0){
					continue;
				}
				if(y==1){
					if(tizu[x][y]==0) dp[x][y]+=1;
					continue;
				}
				if(y==maxY+1){
					if(tizu[x][y-1]==0) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-1]==2) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-2]==2) dp[x][y]+=dp[x][y-2];
					continue;
				}
				if(tizu[x][y]==0){
					if(tizu[x-1][y-1]==0) dp[x][y]+=dp[x-1][y-1];
					if(tizu[x][y-1]==0)   dp[x][y]+=dp[x][y-1];
					if(tizu[x+1][y-1]==0) dp[x][y]+=dp[x+1][y-1];
					if(tizu[x][y-2]==2)   dp[x][y]+=dp[x][y-2];
					continue;
				}
				if(tizu[x][y]==1){
					continue;
				}
				if(tizu[x][y]==2){
					if(tizu[x][y-1]==0) dp[x][y]+=dp[x][y-1];
					if(tizu[x][y-2]==2) dp[x][y]+=dp[x][y-2];
					continue;
				}
			}
		}
/*
		FOR(y,0,maxY+2){
			FOR(x,0,maxY+2){
				cout << dp[x][y];
			}
			cout << endl;
		}
*/


		int res = 0;
		FOR(x,1,maxX+1){ res += dp[x][maxY+1];};
		cout << res << endl;

	}
}