#K64617. Grid Paths with Obstacles

    ID: 32016 Type: Default 1000ms 256MiB

Grid Paths with Obstacles

Grid Paths with Obstacles

You are given a grid of size N x M where each cell is either open (denoted by .) or blocked (denoted by #). Your task is to compute the number of distinct paths from the top-left cell to the bottom-right cell, moving only right or down at each step. Some cells may be blocked, preventing passage through them.

The answer should be computed modulo \(1000000007\).

Example: For a grid of size 3 x 3 as shown below:

... 
.#. 
...

There are exactly 2 distinct paths from the top-left to the bottom-right cell.

inputFormat

Input Format:

  • The first line contains two integers N and M representing the number of rows and columns, respectively.
  • The following N lines each contain a string of length M consisting of characters '.' (open) and '#' (blocked) that represent the grid.

outputFormat

Output Format:

  • Output a single integer denoting the number of distinct paths from the top-left to the bottom-right cell, computed modulo \(1000000007\).
## sample
3 3
...
.#.
...
2