Superjump in a grid
Practice
4.8 (6 votes)
Algorithms
Dynamic programming
2d dynamic programming
Problem
91% Success 1853 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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'.
Submissions
Please login to view your submissions
Similar Problems
Points:20
11 votes
Tags:
AlgorithmsDynamic ProgrammingEasyTwo dimensional
Points:20
33 votes
Tags:
ApprovedBasic ProgrammingEasyOpenTwo dimensional
Points:20
19 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingEasyOpen
Editorial