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>
using namespace std;
int w,h,mp[20][20],memo[20][20];
int dx[] = {-1,0,1};

void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = x+dx[i], ny = y+1;
      if(nx==x && mp[ny][nx] == 2)while(mp[ny][nx] == 2) ny+=2;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;
      if(memo[ny][nx] ==0) saiki(nx,ny);
      memo[y][x] += memo[ny][nx];
    }
  }
  if(memo[y][x] == 0) mp[y][x] = 1;
}
   
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
     
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
  
    for(int i=0;i<w;i++)
      if(mp[0][i] !=1) saiki(i,0);
     
    int cnt = 0;
    for(int i=0;i<w;i++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    while (true) {
        int X, Y;
        cin >> X >> Y;
        
        if (X==0 && Y==0) {
            break;
        }
        
        int c[Y][X];
        
        for (int i=0; i<Y; i++) {
            for (int j=0; j<X; j++) {
                cin >> c[i][j];
            }
        }

        int dp[Y][X];
        
        for (int i=0; i<Y; i++) {
            for (int j=0; j<X; j++) {
                dp[i][j] = 0;
            }
        }
        
        for (int i=0; i<X; i++) {
            if (c[0][i]==0) {
                dp[0][i] = 1;
            }
        }
        
        for (int i=0; i<Y-1; i++) {
            for (int j=0; j<X; j++) {
                if (c[i][j]==0) {
                    if (c[i+1][j]==0 || c[i+1][j]==2) {
                        dp[i+1][j] += dp[i][j];
                    }
                
                    if (j-1>=0) {
                        if (c[i+1][j-1]==0) {
                            dp[i+1][j-1] += dp[i][j];
                        }
                    }
                
                    if (j+1<X) {
                        if (c[i+1][j+1]==0) {
                            dp[i+1][j+1] += dp[i][j];
                        }
                    }
                }
                else if (i<Y-2 && c[i][j]==2) {
                    if (c[i+2][j]!=1) {
                        dp[i+2][j] += dp[i][j];
                    }
                }
            }
        }
        
        int ans = 0;
        
        for (int i=0; i<X; i++) {
            if (c[Y-2][i]==2) {
                ans += dp[Y-2][i];
            }
        }
        
        for (int i=0; i<X; i++) {
            ans += dp[Y-1][i];
        }
        
        cout << ans << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;
int X,Y,imap[20][20];
const int dx[3] = {-1,0,1};
const int dy[3] = {1,1,1};
int sam,dp[20][20];

int solve(){
  
  int ans = 0;
  for(int i=0;i<=Y;i++)for(int j=0;j<=X;j++)dp[i][j] = (i==0 && imap[i][j] != 1)?1:0; 

  for(int i=0;i<Y-1;i++){
    for(int j=0;j<X;j++){
      if(dp[i][j] == 0 || imap[i][j] == 1)continue;
      if(imap[i][j] == 0){
	for(int k=0;k<3;k++){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(0<= nx && nx<X && 0<= ny && ny < Y && imap[ny][nx] != 1){
	      if((k == 0 || k == 2) && imap[ny][nx] == 2)continue;
	      dp[ny][nx]+=dp[i][j];
	  }
	}
      }
      else if(imap[i][j] == 2){
	if(i+2 <Y && imap[i+2][j] != 1){
	  dp[i+2][j]+=dp[i][j];
	}
	else if(i+2 >= Y){
	  if(imap[Y-1][j] != 1)dp[Y-1][j]+=dp[i][j];
	}
      }
    }
  }
  /*
  cout << endl;
    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++)cout << dp[i][j] << " ";
	cout << endl;
    }
  */
    for(int i=0;i<X;i++)ans += dp[Y-1][i];
    return ans;
}



bool Init(){
  cin >> X >> Y;
  if(X+Y == 0)return false;
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++){
      cin >> imap[i][j];
    }
  }
  sam = 0;
  return true;
}


int main(){
  while(true){
    if(!Init())break;
    cout << solve() << endl;
  }
  return 0;
}

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

struct Skier {
	int naname{ 0 }, straight{ 1 }, fling{ 0 };
	int land() const { return naname + straight; }
};
class Field {
	enum class State : char {
		Plane, Tree, Jump
	};
public:
	Field(const int &ah, const int &aw) :h{ ah }, w{ aw }, map(ah, std::vector<State>(aw)) {
		int a;
		for (auto &line : map) {
			for (auto &cell : line) {
				std::cin >> a;
				switch (a) {
				case 0: cell = State::Plane; break;
				case 1: cell = State::Tree; break;
				case 2: cell = State::Jump; break;
				}
			}
		}
	}
	int cul_route() const;
private:
	std::vector<std::vector<State>> map;
	int h, w;
};
int Field::cul_route() const {
	std::vector<std::vector<Skier>> temp_route(h, std::vector<Skier>(w + 2));
	for (auto y = 0; y < temp_route.size() - 1; ++y) {
		for (auto x = 1; x <= w; ++x) {
			switch(map[y][x - 1]) {
			case State::Plane:
				temp_route[y + 1][x - 1].naname += temp_route[y][x].land();
				temp_route[y + 1][x + 1].naname += temp_route[y][x].land();
				temp_route[y + 1][x].straight = temp_route[y][x].land() + temp_route[y][x].fling;
				break;
			case State::Jump:
				temp_route[y + 1][x].fling = temp_route[y][x].straight;
			case State::Tree:
				temp_route[y + 1][x].straight = temp_route[y][x].fling;
			}
		}
	}
	int sum = 0;
	for (auto x = 1; x <= w; ++x) {
		switch (map[h - 1][x - 1]) {
		case State::Plane:
			sum += temp_route[h - 1][x].naname;
		case State::Jump:
			sum += temp_route[h - 1][x].straight;
		case  State::Tree:
			sum += temp_route[h - 1][x].fling;
		}
	}
	return sum;
}
int main() {
	int h, w;
	while (std::cin >> h >> w && h != 0 && w != 0) {
		Field field(h, w);
		std::cout << field.cul_route() << std::endl;
	}
	return 0;
}