#K44242. Unique Paths with Obstacles
Unique Paths with Obstacles
Unique Paths with Obstacles
You are given a grid with (R) rows and (C) columns, where the cells are indexed from (1) to (R) and (1) to (C) respectively. Some cells in the grid are blocked, and you cannot step on them. Starting from the top-left cell ((1, 1)) and aiming to reach the bottom-right cell ((R, C)), you can move only to the right or down. Your task is to calculate the number of distinct paths from the start to the destination, modulo (10^9+7).
Note: If either the starting cell or the destination cell is blocked, there is no valid path.
inputFormat
The input is provided from standard input in the following format:
- The first line contains three integers \(R\), \(C\), and \(N\) representing the number of rows, columns, and the number of blocked cells respectively.
- The next \(N\) lines each contain two integers \(r\) and \(c\), which denote the row and column of a blocked cell.
outputFormat
Output a single integer to standard output: the number of distinct paths from the top-left to the bottom-right cell modulo (10^9+7).## sample
3 3 1
2 2
2