#C8925. Unique Paths in a Matrix with Obstacles
Unique Paths in a Matrix with Obstacles
Unique Paths in a Matrix with Obstacles
You are given a matrix of dimensions \(m \times n\), where each cell is either open ('.') or blocked ('#'). Starting from the top-left corner (cell \(1,1\)) and moving only right or down, your task is to determine the number of distinct paths to reach the bottom-right corner (cell \(m,n\)).
If a cell is blocked, you cannot pass through it. The number of paths is determined using the following recurrence (for open cells):
\[ \text{dp}[i][j] = \text{dp}[i-1][j] + \text{dp}[i][j-1] \]
with the initialization \(\text{dp}[0][0] = 1\) if the start cell is open, and 0 otherwise. Print the result as a single integer which is the number of unique paths available.
inputFormat
The first line contains two space-separated integers \(m\) and \(n\) representing the number of rows and columns in the matrix, respectively.
Each of the next \(m\) lines contains \(n\) space-separated characters (each either '.' or '#') representing the grid.
outputFormat
Output a single integer, the number of unique paths from the top-left to the bottom-right corner of the matrix.
## sample3 3
. . .
. # .
. . .
2