Class Solution
java.lang.Object
g1201_1300.s1219_path_with_maximum_gold.Solution
1219 - Path with Maximum Gold.<p>Medium</p>
<p>In a gold mine <code>grid</code> of size <code>m x n</code>, each cell in this mine has an integer representing the amount of gold in that cell, <code>0</code> if it is empty.</p>
<p>Return the maximum amount of gold you can collect under the conditions:</p>
<ul>
<li>Every time you are located in a cell you will collect all the gold in that cell.</li>
<li>From your position, you can walk one step to the left, right, up, or down.</li>
<li>You can’t visit the same cell more than once.</li>
<li>Never visit a cell with <code>0</code> gold.</li>
<li>You can start and stop collecting gold from <strong>any</strong> position in the grid that has some gold.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> grid = [[0,6,0],[5,8,7],[0,9,0]]</p>
<p><strong>Output:</strong> 24</p>
<p><strong>Explanation:</strong></p>
<pre><code> [[0,6,0],
[5,8,7],
[0,9,0]]
Path to get the maximum gold, 9 -> 8 -> 7.
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]</p>
<p><strong>Output:</strong> 28</p>
<p><strong>Explanation:</strong></p>
<pre><code> [[1,0,7],
[2,0,6],
[3,4,5],
[0,3,0],
[9,0,20]]
Path to get the maximum gold, 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7.
</code></pre>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 <= m, n <= 15</code></li>
<li><code>0 <= grid[i][j] <= 100</code></li>
<li>There are at most <strong>25</strong> cells containing gold.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
getMaximumGold
public int getMaximumGold(int[][] grid)
-