Paths through a blocked grid
An R × C grid has free cells (.) and blocked cells (#). Starting at the top-left cell, you move one step right, one step down or one step diagonally down-right, only onto free cells. Count the paths to the bottom-right cell, modulo 10^9 + 7 (0 if the start or end is blocked).
Input
First line: R and C. Next R lines: the grid rows.
Output
The number of paths modulo 10^9 + 7.
Constraints
1 ≤ R, C ≤ 1000.
Example 1
Input:
2 2
..
..
Output:
3Example 2
Input:
3 3
...
.#.
...
Output:
4Example 3
Input:
3 4
..#.
....
#...
Output:
19Hint: ways[r][c] = ways[r − 1][c] + ways[r][c − 1] + ways[r − 1][c − 1] for a free cell and 0 for a blocked one, filled row by row from the top-left.