#K90652. Count Distinct Paths in a Grid
Count Distinct Paths in a Grid
Count Distinct Paths in a Grid
You are given an n x m grid consisting of characters '.' and '*'. Each '.' represents a free cell, and each '*' represents an obstacle. Starting from the top-left corner (cell (1,1)) and moving to the bottom-right corner (cell (n,m)), you are only allowed to move right or down at any step.
Your task is to count the number of distinct paths from the top-left to the bottom-right cell avoiding obstacles. Since the answer can be very large, output it modulo \(10^9+7\).
Note: If the starting cell or the destination cell is an obstacle, then there is no valid path.
inputFormat
The input is given via standard input (stdin) in the following format:
n m row1 row2 ... row_n
Here, the first line contains two integers n
and m
(1 ≤ n, m ≤ 1000), representing the number of rows and columns respectively. The next n
lines each contain a string of length m
composed only of the characters '.' and '*'.
outputFormat
Output a single integer on standard output (stdout): the number of distinct paths from the top-left corner to the bottom-right corner of the grid, modulo \(10^9+7\).
## sample3 3
...
.*.
...
2