-30. From One Corner to Another with Obstacles

I'm a slow walker, but I never walk backwards.

題目來源:judgegirl from ntu prof. pangfeng Liu

Description

Write a program to compute the number of ways to go from the lower left corner of a matrix to upper right corner. The matrix has rows and columns. You can only move one cell to another cell, and only to the right or to the top. Also there are obstacles in the matrix and you cannot go into any cell that is obstacle . Please compute the number of ways you can go. Note that you are strongly suggested to think in "recursion" to solve this problem.

Limits

Both and are no more than .

Input Format

There are lines in the input. The first line has and . The next lines have the status of the matrix. A 1 indicates a cell you can go through, and a 0 is an obstacle. Both the lower left and upper right corners are 1's.

Sample input

8 3
1 1 1
1 1 1
0 1 1
1 1 1
0 1 1
0 0 1
1 1 1
1 1 1

Sample output

3

Submit

Login

Testdata Set

Download Testdata