1219. Path with Maximum Gold Medium

@problem@discussion
#Array#Backtracking#Matrix



1/**
2 * [1219] Path with Maximum Gold
3 *
4 * In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty.
5 * Return the maximum amount of gold you can collect under the conditions:
6 * 
7 * 	Every time you are located in a cell you will collect all the gold in that cell.
8 * 	From your position, you can walk one step to the left, right, up, or down.
9 * 	You can't visit the same cell more than once.
10 * 	Never visit a cell with 0 gold.
11 * 	You can start and stop collecting gold from any position in the grid that has some gold.
12 * 
13 *  
14 * Example 1:
15 * 
16 * Input: grid = [[0,6,0],[5,8,7],[0,9,0]]
17 * Output: 24
18 * Explanation:
19 * [[0,6,0],
20 *  [5,8,7],
21 *  [0,9,0]]
22 * Path to get the maximum gold, 9 -> 8 -> 7.
23 * 
24 * Example 2:
25 * 
26 * Input: grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]
27 * Output: 28
28 * Explanation:
29 * [[1,0,7],
30 *  [2,0,6],
31 *  [3,4,5],
32 *  [0,3,0],
33 *  [9,0,20]]
34 * Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
35 * 
36 *  
37 * Constraints:
38 * 
39 * 	m == grid.length
40 * 	n == grid[i].length
41 * 	1 <= m, n <= 15
42 * 	0 <= grid[i][j] <= 100
43 * 	There are at most 25 cells containing gold.
44 * 
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/path-with-maximum-gold/
49// discuss: https://leetcode.com/problems/path-with-maximum-gold/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54    pub fn get_maximum_gold(grid: Vec<Vec<i32>>) -> i32 {
55        0
56    }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_1219() {
67    }
68}
69


Back
© 2025 bowen.ge All Rights Reserved.