2023-12-09 18:42:21 +08:00
|
|
|
|
<p>给你一个 <code>n x n</code> 整数矩阵 <code>grid</code> ,请你返回 <strong>非零偏移下降路径</strong> 数字和的最小值。</p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p><strong>非零偏移下降路径</strong> 定义为:从 <code>grid</code> 数组中的每一行选择一个数字,且按顺序选出来的数字中,相邻数字不在原数组的同一列。</p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p><strong class="example">示例 1:</strong></p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
|
|
|
|
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/08/10/falling-grid.jpg" style="width: 244px; height: 245px;" /></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入:</strong>grid = [[1,2,3],[4,5,6],[7,8,9]]
|
2022-03-27 20:37:52 +08:00
|
|
|
|
<strong>输出:</strong>13
|
|
|
|
|
<strong>解释:</strong>
|
|
|
|
|
所有非零偏移下降路径包括:
|
|
|
|
|
[1,5,9], [1,5,7], [1,6,7], [1,6,8],
|
|
|
|
|
[2,4,8], [2,4,9], [2,6,7], [2,6,8],
|
|
|
|
|
[3,4,8], [3,4,9], [3,5,7], [3,5,9]
|
|
|
|
|
下降路径中数字和最小的是 [1,5,7] ,所以答案是 13 。
|
|
|
|
|
</pre>
|
|
|
|
|
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<p><strong class="example">示例 2:</strong></p>
|
2022-03-27 20:37:52 +08:00
|
|
|
|
|
|
|
|
|
<pre>
|
|
|
|
|
<strong>输入:</strong>grid = [[7]]
|
|
|
|
|
<strong>输出:</strong>7
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>n == grid.length == grid[i].length</code></li>
|
|
|
|
|
<li><code>1 <= n <= 200</code></li>
|
|
|
|
|
<li><code>-99 <= grid[i][j] <= 99</code></li>
|
|
|
|
|
</ul>
|