Skip to content
UPEEC

Grid Paths with Obstacles

Medium#dynamic-programming#matrix#combinatorics· solved by 0 · time limit 2.0 s

Count the paths from the top-left to the bottom-right cell moving only right or down, avoiding cells marked 1. Print modulo 109+710^9+7.

Input

RR and CC, then RR rows of CC values (0 = free, 1 = blocked).

Output

The number of paths.

Constraints

1≤R,C≤10001 \le R, C \le 1000

Sample 1

Input

3 3
0 0 0
0 1 0
0 0 0

Output

2

Sign in or join free to run and submit your solution.