2328. Number of Increasing Paths in a Grid Hard
#Array#Dynamic Programming#Depth-First Search#Breadth-First Search#Graph#Topological Sort#Memoization#Matrix
1/**
2 * [2328] Number of Increasing Paths in a Grid
3 *
4 * You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.
5 * Return the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10^9 + 7.
6 * Two paths are considered different if they do not have exactly the same sequence of visited cells.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2022/05/10/griddrawio-4.png" style="width: 181px; height: 121px;" />
10 * Input: grid = [[1,1],[3,4]]
11 * Output: 8
12 * Explanation: The strictly increasing paths are:
13 * - Paths with length 1: [1], [1], [3], [4].
14 * - Paths with length 2: [1 -> 3], [1 -> 4], [3 -> 4].
15 * - Paths with length 3: [1 -> 3 -> 4].
16 * The total number of paths is 4 + 3 + 1 = 8.
17 *
18 * Example 2:
19 *
20 * Input: grid = [[1],[2]]
21 * Output: 3
22 * Explanation: The strictly increasing paths are:
23 * - Paths with length 1: [1], [2].
24 * - Paths with length 2: [1 -> 2].
25 * The total number of paths is 2 + 1 = 3.
26 *
27 *
28 * Constraints:
29 *
30 * m == grid.length
31 * n == grid[i].length
32 * 1 <= m, n <= 1000
33 * 1 <= m * n <= 10^5
34 * 1 <= grid[i][j] <= 10^5
35 *
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/number-of-increasing-paths-in-a-grid/
40// discuss: https://leetcode.com/problems/number-of-increasing-paths-in-a-grid/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45 pub fn count_paths(grid: Vec<Vec<i32>>) -> i32 {
46 0
47 }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn test_2328() {
58 }
59}
60
Back
© 2025 bowen.ge All Rights Reserved.