#C7555. Robot Paths in a Grid

    ID: 51439 Type: Default 1000ms 256MiB

Robot Paths in a Grid

Robot Paths in a Grid

You are given a grid with R rows and C columns. Each cell of the grid is either passable ('.') or blocked ('#'). A robot is initially positioned in the top-left corner of the grid (cell (1,1)) and needs to reach the bottom-right corner (cell (R,C)). The robot can only move either to the right or down at any step. Your task is to compute the number of distinct paths from the start to the finish, while avoiding obstacles. Since the answer can be very large, output the result modulo \(10^9+7\).

Note: A cell containing '#' is an obstacle and cannot be traversed. It is guaranteed that movement is only allowed to the right or down, and paths that go through a blocked cell are invalid.

inputFormat

The input is provided via standard input (stdin) and consists of:

  • The first line contains two integers R and C separated by a space, representing the number of rows and columns in the grid.
  • The following R lines each contain C characters separated by a space. Each character is either '.' representing an open cell or '#' representing an obstacle.

For example:

3 4
. . . .
. # . .
. . . .

outputFormat

Print a single integer to standard output (stdout) which is the number of distinct valid paths from the top-left corner to the bottom-right corner modulo \(10^9+7\).

## sample
1 1
.
1