You are given a $$N * M$$ grid in which each cell consists of either 0 or 1. A cell $$(i,j)$$ is blocked if its value is 1. Standing at a cell $$(i,j)$$, you can perform the following steps.
- You can move right to the very next cell which is not blocked.
- You can move down to the very next cell which is not blocked.
You are initially located at cell $$(1,1)$$. Determine the number of ways in which you can reach $$(N, M)$$ starting from your initial location.
Since the answer can be large, print it modulo (\(10^9 + 7\)).
Example: Let 3 * 3 grid be
0 | 1 | 0 |
1 | 0 | 0 |
0 | 0 | 0 |
If you are standing at cell (1,1), then:
- By performing step 1, you can jump to cell (1,3) and,
- By performing step 2, you can jump to cell (3,1)
The answer will be 2.
Input format
- The first line contains $$N$$ and $$M$$ denoting the number of rows and the number of columns.
- Each of the next $$N$$ lines consists of a string of length $$M$$.
Output format
Print a single line containing the number of ways to reach $$(N, M)$$ from $$(1,1)$$ modulo \(10^9 + 7\).
Constraints
\(1 \le N, M \le 1000\)
Each cell consists of either '0' or '1'.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial