576. Out of Boundary Paths Medium

@problem@discussion
#Dynamic Programming



1/**
2 * [576] Out of Boundary Paths
3 *
4 * There is an m x n grid with a ball. The ball is initially at the position [startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid (possibly out of the grid crossing the grid boundary). You can apply at most maxMove moves to the ball.
5 * Given the five integers m, n, maxMove, startRow, startColumn, return the number of paths to move the ball out of the grid boundary. Since the answer can be very large, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/28/out_of_boundary_paths_1.png" style="width: 500px; height: 296px;" />
9 * Input: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0
10 * Output: 6
11 * 
12 * Example 2:
13 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/28/out_of_boundary_paths_2.png" style="width: 500px; height: 293px;" />
14 * Input: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1
15 * Output: 12
16 * 
17 *  
18 * Constraints:
19 * 
20 * 	1 <= m, n <= 50
21 * 	0 <= maxMove <= 50
22 * 	0 <= startRow < m
23 * 	0 <= startColumn < n
24 * 
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/out-of-boundary-paths/
29// discuss: https://leetcode.com/problems/out-of-boundary-paths/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34    pub fn find_paths(m: i32, n: i32, max_move: i32, start_row: i32, start_column: i32) -> i32 {
35        0
36    }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_576() {
47    }
48}
49


Back
© 2025 bowen.ge All Rights Reserved.