#C9107. Distinct Paths on a Magic Grid
Distinct Paths on a Magic Grid
Distinct Paths on a Magic Grid
You are given an N × N grid where each cell is assigned a magic power value. Your task is to determine the number of distinct paths from the top-left corner to the bottom-right corner such that every cell on the path has a magic power greater than or equal to a given threshold T.
You may only move either right or down at each step.
The answer should be computed modulo \(10^9+7\).
Input Constraints:
- The first line contains two integers \(N\) and \(T\).
- The following \(N\) lines each contain \(N\) integers representing the grid.
Output:
Output a single integer: the number of valid paths modulo \(10^9+7\). If no valid path exists, output 0.
inputFormat
The input is given via standard input. The first line contains two integers \(N\) and \(T\) separated by a space.
Each of the next \(N\) lines contains \(N\) integers separated by spaces, representing the grid values.
\(N\) represents the size of the grid (rows and columns) and \(T\) is the threshold for the magic power. A cell \(P[i][j]\) is valid if \(P[i][j] \ge T\).
outputFormat
Output a single integer, which is the count of distinct valid paths from the top-left corner to the bottom-right corner, calculated modulo \(10^9+7\).
## sample3 5
7 8 3
4 9 5
3 6 10
2