Problems > Paths Around the Walls

Paths Around the Walls

Difficulty: 1500 2000 ms 128 MB

dp

Count the right/down paths from the top-left to the bottom-right of a grid, avoiding wall cells (#), modulo 109+7.

Input: the first line has N and M; the next N lines each have M characters (. free, # wall).

Output: the number of paths mod 109+7.

Constraints:

  • 1 ≤ N, M ≤ 1000

Sample Tests

Input 1
3 3
...
.#.
...
Output 1
2
Input 2
1 1
.
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.