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 <vector>

enum class State {
	Empty, Tree, Jump
};
class Ski_run {
public:
	Ski_run(const int &x, const int &y) :width(x), height(y), state(y, std::vector<State>(x, State::Empty)), route(y + 1, std::vector<long long int>(x, 0)), null(0), res(-1) {
		for (auto &line : state) {
			for (auto &c : line) {
				int a;
				std::cin >> a;
				c = static_cast<State>(a);
			}
		}
		state.push_back(std::vector<State>(width, State::Empty));
		state.push_back(std::vector<State>(width, State::Empty));
		route.at(height) = std::vector<long long int>(x, 1);
		route.at(height - 1) = std::vector<long long int>(x, 1);
	}
	void show() const {
		for (const auto &l : route) {
			for (const auto &c : l) {
				std::cout << c;
			}
			std::cout << '\n';
		}
	}
	long long int solve() {
		if (res >= 0) {
			return res;
		}
		else {
			for (auto y = height - 2; y >= 0; --y) {
				for (auto x = 0; x < width; ++x) {
					switch (state.at(y).at(x)) {
					case State::Empty:
						if (at(x - 1, y + 1) == State::Empty) {
							route.at(y).at(x) += route.at(y + 1).at(x - 1);
						}
						if (at(x + 1, y + 1) == State::Empty) {
							route.at(y).at(x) += route.at(y + 1).at(x + 1);
						}
						if (!(at(x, y + 1) == State::Tree)) { 
							route.at(y).at(x) += route.at(y + 1).at(x);
						}
						break;
					case State::Jump:
						if (!(at(x, y + 2) == State::Tree)) {
							route.at(y).at(x) += route.at(y + 2).at(x);
						}
					}
				}
			}
			res = 0;
			for (const auto &l : route.at(0)) {
				res += l;
			}
			return res;
		}
	}
private:
	State at(const int &x, const int &y) {
		if (x >= 0 && width > x) {
			return state.at(y).at(x);
		}
		else {
			return State::Tree;
		}
	}
	int width, height;
	std::vector<std::vector<long long int>> route;
	std::vector<std::vector<State>> state;
	int null, res;
};
int main() {
	int x, y;
	std::cin >> x >> y;
	while (x != 0 || y != 0) {
		Ski_run state(x, y);
		std::cout << state.solve() << std::endl;
		std::cin >> x >> y;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#define pf p.first
#define ps p.second
using namespace std;
typedef pair<int,int>P;
int h,w,mas[20][20],memo[20][20],ans,tmp[]={-1,0,1};
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int dfs(P);
int main(){
  while(cin >> w >> h && w||h){
    ans = 0;
    for(int i=0;i<20;i++) for(int j=0;j<20;j++) memo[i][j] = -1;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> mas[i][j];
    for(int i=0;i<w;i++) ans += dfs(P(0,i));
    cout << ans << endl;
  }
}
int dfs(P p){
  if(memo[pf][ps] != -1) return memo[pf][ps];
  if(pf >= h - 1) return 1;//OK
  if(mas[pf][ps] == 1) return 0;//NO
  else if(mas[pf][ps] == 2) return (memo[pf][ps] = dfs(P(pf+2,ps)));
  else{
    int cnt = 0;
    for(int i=0;i<3;i++){
      int nx = pf + 1,ny = ps + tmp[i];
      if(ny>=0&&ny<w&&((mas[nx][ny]==0)||(mas[nx][ny]==2&&i==1))){
	  cnt += dfs(P(pf+1,ps+tmp[i]));
	}
    }
    return (memo[pf][ps] = cnt);
  }
}

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 >> m >> n && 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];
      }
    }
    
    int dp[30][30][2] = {{{}}};
    
    for(int j=0; j<m; j++) {
      if(grid[0][j]==0) { dp[0][j][0] = 1; }
    }
    
    int extra = 0;
    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)) continue;
	
	// A skier is at a ski jump.
	if(isAtSkiJump(j, i)) {
	  if(i+2 > n-1) extra += 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 + extra << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int x, y;
int field[16][16];
int dp[16][16];

int main(){
	while (cin >> x >> y&&x + y){
		REP(i, 16){
			REP(j, 16){
				dp[i][j] = 0;
				field[i][j] = 0;
			}
		}
		REP(i, y)REP(j, x)cin >> field[i][j];
		REP(j, x){
			if (field[0][j] == 0)dp[0][j] = 1;
		}
		REP(i, y-1){
			REP(j, x){
				if (field[i][j] == 0){
					if (field[i + 1][j] != 1)dp[i + 1][j] += dp[i][j];
					if (j - 1 >= 0 && field[i + 1][j - 1] == 0){
						dp[i + 1][j - 1] += dp[i][j];
					}
					if (j + 1 < x&&field[i + 1][j + 1] == 0){
						dp[i + 1][j + 1] += dp[i][j];
					}
				}
				else if (field[i][j] == 2){
					if (i <= y - 3 && dp[i + 2][j] != 1){
						dp[i + 2][j] += dp[i][j];
					}
					else if (i == y - 2){
						dp[i + 1][j] += dp[i][j];
					}
				}
			}
		}
		//cout << endl;
		//REP(i, y + 1){
		//	REP(j, x){
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;
		//}
		int ans = 0;
		REP(j, x)ans += dp[y-1][j];
		cout << ans << endl;
	}
}