Problem:


会津山スキー場の新企画

 会津山スキー場の経営者である油木屋さんは、上級者向けとして障害物やジャンプ台を配置したコースを用意しました。コースにはいろいろな滑り方があり、シーズン中に全てのパターンの滑り方が出来た利用者には、プレゼントを贈ることになっています。

油木屋さんのために、コースの見取り図をもとに滑り方のパターン数を出力するプログラムを作ってあげましょう。

  コースは上図のような X &times; Y 個のマスからなるグリッドで表されます。左上を原点とし、x 座標は右に行くにつれて大きくなり、y 座標は下にいくにつれて大きくなるものとします。

 各滑り方のパターンは、最も高いところ(y = 1 、ただし障害物の無いところ) からスタートし、ゴール(y = Y) に向かって進んでいきます。グリッドのマス(x, y) にいる滑走者は、(x &minus; 1, y + 1)、(x, y + 1)、 (x + 1, y + 1) のいずれかに移動することができます。マスには、障害物やジャンプ台があり、障害物のあるマスには進入できず、ジャンプ台があるマスに進入すると(x, y + 2) へ移動します。ただし、いちばん高いマス (y = 1 のマス) にはジャンプ台は存在せず、ジャンプ台のあるマスに進入する際には x 座標が同じマスからしか進入できません。コースの上端(y = 1) からスタートし、コースからはずれることなく下端を超えれば(y ≥ Y) 1つの滑り方とみなし、滑り終わります。

  コースの情報を入力とし、滑り方の総数を出力するプログラムを作成してください。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロふたつの行で示されます。各データセットは以下の形式で与えられます。

X Y
c11 c21 ... cX1
c12 c22 ... cX2
:
c1Y c2Y ... cXY	

1 行目にコースの大きさX, Y (1 ≤ X, Y ≤ 15) が与えられます。続く Y 行にコースの情報が与えられます。cij (0 , 1 , 2 のいずれか) はx = i, y = j のマスの情報を表す整数で、0 が移動可能なマス、1 が障害物があるマス、2 がジャンプ台があるマスを表します。

データセットの数は 50 を超えません。

Output

入力データセットごとに、コースの滑り方のパターン数を1行に出力します。

Sample Input

5 5
0 0 0 0 1
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
5 5
0 0 1 0 0
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
15 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0

Output for the Sample Input

8
6
52694573



Sample input:
5 5
0 0 0 0 1
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
5 5
0 0 1 0 0
2 1 0 2 0
1 0 0 1 1
0 2 1 2 0
0 1 0 0 0
15 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0


Sample output:
8
6
52694573

Submission status: Wrong Answer

Solution code:
while(1):
    [X,Y]=[int(x) for x in raw_input().split()]
    if X==0:
        break
    else:
        F=[]
        for i in range(Y):
            F.append([0]+[int(x) for x in raw_input().split()]+[0])
        F.append([3 for x in range(X+2)])
        F.append([3 for x in range(X+2)])        
        S=[[0 for x in range(X+2)] for y in range(Y+2)] #F,S[y][x]
        #initilizing
        for i in range(1,X+1):
            S[0][i]=1-F[0][i]
        for j in range(Y+2):
            for i in range(1,X+1):
                if F[j][i]==2:
                    S[j][i]=S[j][i]+S[j-1][i]
                    S[j+2][i]=S[j+2][i]+S[j][i]
                elif F[j][i]==1:
                    S[j][i]=0
                elif F[j][i]==3:
                    S[j][i]=S[j][i]+S[j-1][i]
                else:
                    S[j][i]=S[j][i]+(1-F[j-1][i]/2)*S[j-1][i]+(1-F[j-1][i-1]/2)*S[j-1][i-1]+(1-F[j-1][i+1]/2)*S[j-1][i+1]
        print sum(S[Y])

Submission status: Wrong Answer

Solution code:
""" Created by Jieyi on 8/16/16. """


def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0:
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
""" Created by Jieyi on 8/16/16. """


def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if in_map[i][j] == 2:
                        down_jump(i, j, out_map[i][j])
                    elif i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if in_map[i][j] == 2:
                        down_jump(i, j, out_map[i][j])
                    elif i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        for i in range(c):
            out_map[r - 1][i] = 0 if in_map[r - 1][i] else out_map[r - 1][i]
        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if in_map[i][j] == 2:
                        down_jump(i, j, out_map[i][j])
                    elif i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        for i in range(c):
            out_map[r - 1][i] = 0 if in_map[r - 1][i] and in_map[r - 2][i] != 2 else out_map[r - 1][i]
        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def algorithm():
    def down_jump(x, y, times):
        if r == 1:
            return
        elif x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if in_map[i][j] == 2:
                        down_jump(i, j, out_map[i][j])
                    elif i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        for i in range(c):
            out_map[r - 1][i] = 0 if in_map[r - 1][i] and in_map[r - 2][i] != 2 else out_map[r - 1][i]
        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)

    return 0

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == 1:  #  ?????£????????§?????°?????????????????????
            continue
        elif field[cy][cx] == 2: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 >= y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != 1:
                    ans += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)


    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if cy >= y_limit - 1:
            continue

        if field[cy][cx] == 1:  #  ?????£????????§?????°?????????????????????
            continue
        elif field[cy][cx] == 2: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 >= y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != 1:
                    ans += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)


    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == OBSTACLE:
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != OBSTACLE:
                    ans += num
                else:
                    if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == BLANK:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)


    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != OBSTACLE:
                    ans += num
                else:
                    if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == BLANK:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    # dy = [1, 1, 1]
    dx = [0, -1, 1] # ?????????????????????????????????????§???????
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()                 #  ?????§??????????????????????????¨??????????????\???

    # ???????????§??????????????§????????´????????¢???????????\??????????????????
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            k = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[k] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        k = '{}_{}'.format(cx, cy)
        num = path.pop(k)       #  ????????§?¨?????????????????????°

        if field[cy][cx] == OBSTACLE: #  ?????£????????§?????°??????????????????????????±????????????????????????????????§?????£?????????????????
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1: #  ?????£???????????????????¶?????????´??????OK??¨?????????
                ans += num
            else:
                k = '{}_{}'.format(cx, cy+2)
                if not path[k]:
                    Q.append((cx, cy+2))
                path[k] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(3):      #  ?????????3???len(dy)?????????
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + 1         #  ??????+1????????§???dy[i]??¨?????????????????????OK

            if 0<= nx < x_limit:
                if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                    if ny+2 > y_limit - 1:
                        ans += num
                    else:
                        k = '{}_{}'.format(nx, ny+2)
                        if not path[k]:
                            Q.append((nx, ny+2))
                        path[k] += num
                elif field[ny][nx] == BLANK:
                    if (ny >= y_limit - 1):
                        ans += num
                    else:
                        k = '{}_{}'.format(nx, ny)
                        if not path[k]:
                            Q.append((nx, ny))
                        path[k] += num
    return ans


def solve2(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == BLANK:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1

    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if field[cy][cx] == OBSTACLE:
            continue
        elif field[cy][cx] == JUMP: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 > y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue
        elif cy == y_limit -1:
            ans += num
            continue

        for i in range(3):      #  ?????????3???len(dy)?????????
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if field[ny][nx] == JUMP and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                    if ny+2 > y_limit - 1:
                        ans += num
                    else:
                        t = '{}_{}'.format(nx, ny+2)
                        if not path[t]:
                            Q.append((nx, ny+2))
                        path[t] += num
                elif field[ny][nx] == BLANK:
                    if (ny >= y_limit - 1):
                        ans += num
                    else:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def solve3(field):
    BLANK, OBSTACLE, JUMP = 0, 1, 2
    X = len(field[0])
    Y = len(field)
    dp = [[0] * X for _ in range(Y)]

    for x in range(X):
        if field[0][x] == BLANK:
            dp[0][x] = 1

    for y in range(1, Y):
        for x in range(X):
            if field[y][x] == BLANK:
                if field[y-1][x] != JUMP:
                    dp[y][x] = dp[y-1][x]
                if x > 0 and field[y-1][x-1] != JUMP:
                    dp[y][x] += dp[y-1][x-1]
                if x < X-1 and field[y-1][x+1] != JUMP:
                    dp[y][x] += dp[y-1][x+1]
                if y > 1 and field[y-2][x] == JUMP:
                    dp[y][x] += dp[y-2][x]
            elif field[y][x] == OBSTACLE:
                dp[y][x] = 0
            else:
                dp[y][x] = dp[y-1][x]
                if y > 1 and field[y-2][x] == JUMP:
                    dp[y][x] += dp[y-2][x]
    ans = sum(dp[-1])
    if Y > 1:
        for x in range(X):
            if field[-2][x] == JUMP:
                ans += dp[-2][x]
    return ans



def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve3(field)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])