Skip to content

Commit c37d8b9

Browse files
update: 添加问题“2087.网格图中机器人回家的最小代价”的代码和题解 + finish #1480 's 空间优化's todo (#1482)
* 2087: WA.cpp (#1481) * 2087: WA.cpp (#1481) - 不一定是[from + 1] * 2087: AC.cpp (#1481) - AC,100.00%,14.71% * 2087: WA.py (#1481) - min,max * 2087: AC.py (#1481) - AC,84.21%,26.32% * 3418: WA.py (#1481)(#1480) * 3418: AC.py (#1481)(#1480) - AC,38.62%,75.20% * 3418: WA.cpp.O(m) (#1481)(#1480) * 3418: AC.cpp.O(m) (#1481)(#1480) - AC,81.34%,53.35% * update: 添加问题“2087.网格图中机器人回家的最小代价”的代码和题解 (#1482) Signed-off-by: LetMeFly666 <Tisfy@qq.com> * fix: update the 时间复杂度 Update Solutions/LeetCode 3418.机器人可以获得的最大金币数.md Co-authored-by: gh-pr-review[bot] <268385713+gh-pr-review[bot]@users.noreply.github.com> * fix: language Update Solutions/LeetCode 3418.机器人可以获得的最大金币数.md Co-authored-by: gh-pr-review[bot] <268385713+gh-pr-review[bot]@users.noreply.github.com> * fix: duplicated O --------- Signed-off-by: LetMeFly666 <Tisfy@qq.com> Co-authored-by: gh-pr-review[bot] <268385713+gh-pr-review[bot]@users.noreply.github.com>
1 parent 9906caa commit c37d8b9

8 files changed

Lines changed: 312 additions & 7 deletions

.commitmsg

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-04-04 13:57:29
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-04-04 14:05:23
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
class Solution {
12+
public:
13+
int minCost(vector<int>& startPos, vector<int>& homePos, vector<int>& rowCosts, vector<int>& colCosts) {
14+
int ans = 0;
15+
for (int from = startPos[0], to = homePos[0], direction = to > from ? 1 : -1; from != to; from += direction) {
16+
ans += rowCosts[from + direction];
17+
}
18+
for (int from = startPos[1], to = homePos[1], direction = to > from ? 1 : -1; from != to; from += direction) {
19+
ans += colCosts[from + direction];
20+
}
21+
return ans;
22+
}
23+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-04-04 13:57:29
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-04-04 14:10:12
6+
'''
7+
from typing import List
8+
9+
class Solution:
10+
def minCost(self, startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int:
11+
sx, sy = startPos
12+
ex, ey = homePos
13+
return sum(rowCosts[min(sx, ex) : max(sx, ex) + 1]) + sum(colCosts[min(sy, ey) : max(sy, ey) + 1]) - rowCosts[sx] - colCosts[sy]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'''
2+
Author: LetMeFly
3+
Date: 2026-04-04 14:12:53
4+
LastEditors: LetMeFly.xyz
5+
LastEditTime: 2026-04-04 14:23:48
6+
'''
7+
from typing import List
8+
from math import inf
9+
10+
class Solution:
11+
def maximumAmount(self, coins: List[List[int]]) -> int:
12+
n, m = len(coins), len(coins[0])
13+
dp = [[[-inf for _ in range(m)] for _ in range(n)] for _ in range(3)]
14+
dp[0][0][0] = coins[0][0]
15+
dp[1][0][0] = dp[2][0][0] = max(coins[0][0], 0)
16+
17+
for i in range(n):
18+
for j in range(m):
19+
if not i and not j:
20+
continue
21+
for th in range(3):
22+
dp[th][i][j] = max(dp[th][i - 1][j] if i else -inf, dp[th][i][j - 1] if j else -inf) + coins[i][j]
23+
for th in range(1, 3):
24+
dp[th][i][j] = max(dp[th][i][j], dp[th - 1][i - 1][j] if i else -inf, dp[th - 1][i][j - 1] if j else -inf)
25+
26+
return dp[2][n - 1][m - 1]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* @Author: LetMeFly
3+
* @Date: 2026-04-04 14:24:22
4+
* @LastEditors: LetMeFly.xyz
5+
* @LastEditTime: 2026-04-04 14:39:36
6+
*/
7+
#ifdef _DEBUG
8+
#include "_[1,2]toVector.h"
9+
#endif
10+
11+
const int INF = 1e9;
12+
class Solution {
13+
public:
14+
int maximumAmount(vector<vector<int>>& coins) {
15+
int n = coins.size(), m = coins[0].size();
16+
array<vector<int>, 3> dp;
17+
dp.fill(vector<int>(m));
18+
19+
for (int i = 0; i < n; i++) {
20+
array<vector<int>, 3> nextDP;
21+
nextDP.fill(vector<int>(m));
22+
for (int j = 0; j < m; j++) {
23+
if (!i && !j) {
24+
nextDP[0][0] = coins[0][0];
25+
nextDP[1][0] = nextDP[2][0] = max(coins[0][0], 0);
26+
continue;
27+
}
28+
for (int th = 0; th < 3; th++) {
29+
nextDP[th][j] = coins[i][j] + max(i ? dp[th][j] : -INF, j ? nextDP[th][j - 1] : -INF);
30+
}
31+
for (int th = 1; th < 3; th++) {
32+
nextDP[th][j] = max(nextDP[th][j], max(i ? dp[th - 1][j] : -INF, j ? nextDP[th - 1][j - 1] : -INF));
33+
}
34+
}
35+
dp = move(nextDP);
36+
}
37+
38+
return dp[2][m - 1];
39+
}
40+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@
748748
|2079.给植物浇水|中等|<a href="https://leetcode.cn/problems/watering-plants/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/05/08/LeetCode%202079.%E7%BB%99%E6%A4%8D%E7%89%A9%E6%B5%87%E6%B0%B4/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/138581691" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/watering-plants/solutions/2770202/letmefly-2079gei-zhi-wu-jiao-shui-onmo-n-gm33/" target="_blank">LeetCode题解</a>|
749749
|2080.区间内查询数字的频率|中等|<a href="https://leetcode.cn/problems/range-frequency-queries/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/02/18/LeetCode%202080.%E5%8C%BA%E9%97%B4%E5%86%85%E6%9F%A5%E8%AF%A2%E6%95%B0%E5%AD%97%E7%9A%84%E9%A2%91%E7%8E%87/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/145700724" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/range-frequency-queries/solutions/3079246/letmefly-2080qu-jian-nei-cha-xun-shu-zi-u33r8/" target="_blank">LeetCode题解</a>|
750750
|2085.统计出现过一次的公共字符串|简单|<a href="https://leetcode.cn/problems/count-common-words-with-one-occurrence/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2024/01/12/LeetCode%202085.%E7%BB%9F%E8%AE%A1%E5%87%BA%E7%8E%B0%E8%BF%87%E4%B8%80%E6%AC%A1%E7%9A%84%E5%85%AC%E5%85%B1%E5%AD%97%E7%AC%A6%E4%B8%B2/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/135560255" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/count-common-words-with-one-occurrence/solutions/2601942/letmefly-2085tong-ji-chu-xian-guo-yi-ci-cdg6x/" target="_blank">LeetCode题解</a>|
751+
|2087.网格图中机器人回家的最小代价|中等|<a href="https://leetcode.cn/problems/minimum-cost-homecoming-of-a-robot-in-a-grid/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2026/04/04/LeetCode%202087.%E7%BD%91%E6%A0%BC%E5%9B%BE%E4%B8%AD%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%9B%9E%E5%AE%B6%E7%9A%84%E6%9C%80%E5%B0%8F%E4%BB%A3%E4%BB%B7/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/159828365" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/minimum-cost-homecoming-of-a-robot-in-a-grid/solutions/3944603/letmefly-2087wang-ge-tu-zhong-ji-qi-ren-770wf/" target="_blank">LeetCode题解</a>|
751752
|2094.找出3位偶数|简单|<a href="https://leetcode.cn/problems/finding-3-digit-even-numbers/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/05/12/LeetCode%202094.%E6%89%BE%E5%87%BA3%E4%BD%8D%E5%81%B6%E6%95%B0/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/147906775" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/finding-3-digit-even-numbers/solutions/3675405/letmefly-2094zhao-chu-3-wei-ou-shu-bian-ncco6/" target="_blank">LeetCode题解</a>|
752753
|2099.找到和最大的长度为K的子序列|简单|<a href="https://leetcode.cn/problems/find-subsequence-of-length-k-with-the-largest-sum/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2025/07/07/LeetCode%202099.%E6%89%BE%E5%88%B0%E5%92%8C%E6%9C%80%E5%A4%A7%E7%9A%84%E9%95%BF%E5%BA%A6%E4%B8%BAK%E7%9A%84%E5%AD%90%E5%BA%8F%E5%88%97/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/149184546" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-subsequence-of-length-k-with-the-largest-sum/solutions/3717887/letmefly-2099zhao-dao-he-zui-da-de-chang-d621/" target="_blank">LeetCode题解</a>|
753754
|2100.适合打劫银行的日子|中等|<a href="https://leetcode.cn/problems/find-good-days-to-rob-the-bank/" target="_blank">题目地址</a>|<a href="https://blog.letmefly.xyz/2023/09/26/LeetCode%202100.%E9%80%82%E5%90%88%E6%89%93%E5%8A%AB%E9%93%B6%E8%A1%8C%E7%9A%84%E6%97%A5%E5%AD%90/" target="_blank">题解地址</a>|<a href="https://letmefly.blog.csdn.net/article/details/133324938" target="_blank">CSDN题解</a>|<a href="https://leetcode.cn/problems/find-good-days-to-rob-the-bank/solutions/2460364/letmefly-2100gua-he-da-jie-yin-xing-de-r-aqwp/" target="_blank">LeetCode题解</a>|
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
title: 2087.网格图中机器人回家的最小代价:脑筋急转弯(固定走法)
3+
date: 2026-04-04 14:43:15
4+
tags: [题解, LeetCode, 中等, 贪心, 数组, 脑筋急转弯]
5+
categories: [题解, LeetCode]
6+
index_img: https://assets.leetcode.com/uploads/2021/10/11/eg-1.png
7+
---
8+
9+
# 【LetMeFly】2087.网格图中机器人回家的最小代价:脑筋急转弯(固定走法)
10+
11+
力扣题目链接:[https://leetcode.cn/problems/minimum-cost-homecoming-of-a-robot-in-a-grid/](https://leetcode.cn/problems/minimum-cost-homecoming-of-a-robot-in-a-grid/)
12+
13+
<p>给你一个&nbsp;<code>m x n</code>&nbsp;的网格图,其中&nbsp;<code>(0, 0)</code>&nbsp;是最左上角的格子,<code>(m - 1, n - 1)</code>&nbsp;是最右下角的格子。给你一个整数数组&nbsp;<code>startPos</code>&nbsp;,<code>startPos = [start<sub>row</sub>, start<sub>col</sub>]</code>&nbsp;表示 <strong>初始</strong>&nbsp;有一个 <strong>机器人</strong>&nbsp;在格子&nbsp;<code>(start<sub>row</sub>, start<sub>col</sub>)</code>&nbsp;处。同时给你一个整数数组&nbsp;<code>homePos</code>&nbsp;,<code>homePos = [home<sub>row</sub>, home<sub>col</sub>]</code>&nbsp;表示机器人的 <strong>家</strong>&nbsp;在格子&nbsp;<code>(home<sub>row</sub>, home<sub>col</sub>)</code>&nbsp;处。</p>
14+
15+
<p>机器人需要回家。每一步它可以往四个方向移动:<strong>上</strong>,<strong>下</strong>,<strong>左</strong>,<strong>右</strong>,同时机器人不能移出边界。每一步移动都有一定代价。再给你两个下标从&nbsp;<strong>0</strong>&nbsp;开始的额整数数组:长度为&nbsp;<code>m</code>&nbsp;的数组&nbsp;<code>rowCosts</code> &nbsp;和长度为 <code>n</code>&nbsp;的数组&nbsp;<code>colCosts</code>&nbsp;。</p>
16+
17+
<ul>
18+
<li>如果机器人往 <strong>上</strong>&nbsp;或者往 <strong>下</strong>&nbsp;移动到第 <code>r</code>&nbsp;<strong>行</strong>&nbsp;的格子,那么代价为&nbsp;<code>rowCosts[r]</code>&nbsp;。</li>
19+
<li>如果机器人往 <strong>左</strong>&nbsp;或者往 <strong>右</strong>&nbsp;移动到第 <code>c</code>&nbsp;<strong>列</strong> 的格子,那么代价为&nbsp;<code>colCosts[c]</code>&nbsp;。</li>
20+
</ul>
21+
22+
<p>请你返回机器人回家需要的 <strong>最小总代价</strong>&nbsp;。</p>
23+
24+
<p>&nbsp;</p>
25+
26+
<p><strong>示例 1:</strong></p>
27+
28+
<p><img alt="" src="https://assets.leetcode.com/uploads/2021/10/11/eg-1.png" style="width: 282px; height: 217px;"></p>
29+
30+
<pre><strong>输入:</strong>startPos = [1, 0], homePos = [2, 3], rowCosts = [5, 4, 3], colCosts = [8, 2, 6, 7]
31+
<b>输出:</b>18
32+
<b>解释:</b>一个最优路径为:
33+
从 (1, 0) 开始
34+
-&gt; 往下走到 (<em><strong>2</strong></em>, 0) 。代价为 rowCosts[2] = 3 。
35+
-&gt; 往右走到 (2, <em><strong>1</strong></em>) 。代价为 colCosts[1] = 2 。
36+
-&gt; 往右走到 (2, <em><strong>2</strong></em>) 。代价为 colCosts[2] = 6 。
37+
-&gt; 往右走到 (2, <em><strong>3</strong></em>) 。代价为 colCosts[3] = 7 。
38+
总代价为 3 + 2 + 6 + 7 = 18</pre>
39+
40+
<p><strong>示例 2:</strong></p>
41+
42+
<pre><b>输入:</b>startPos = [0, 0], homePos = [0, 0], rowCosts = [5], colCosts = [26]
43+
<b>输出:</b>0
44+
<b>解释:</b>机器人已经在家了,所以不需要移动。总代价为 0 。
45+
</pre>
46+
47+
<p>&nbsp;</p>
48+
49+
<p><strong>提示:</strong></p>
50+
51+
<ul>
52+
<li><code>m == rowCosts.length</code></li>
53+
<li><code>n == colCosts.length</code></li>
54+
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
55+
<li><code>0 &lt;= rowCosts[r], colCosts[c] &lt;= 10<sup>4</sup></code></li>
56+
<li><code>startPos.length == 2</code></li>
57+
<li><code>homePos.length == 2</code></li>
58+
<li><code>0 &lt;= start<sub>row</sub>, home<sub>row</sub> &lt; m</code></li>
59+
<li><code>0 &lt;= start<sub>col</sub>, home<sub>col</sub> &lt; n</code></li>
60+
</ul>
61+
62+
63+
64+
## 解题方法:脑筋急转弯(固定走法)
65+
66+
想想我们是怎么计算代价的,如果上下移动到了某一行,不论是在哪一列移动到的,都加上这一行的“代价”;列同理。
67+
68+
假设起点终点不在同一行,那么竖直方向上从起点到终点的移动是不可避免的。并且我们没有必要往上移动后再往下移动这样来回绕路;竖直方向同理。
69+
70+
也就是说,任何场景我们都直接像样例中那样一个L形路径走过去就行了。
71+
72+
+ 时间复杂度$\mathcal{O}(|start_{row} - home_{row}| + |start_{col} - home_{col}|)$
73+
+ 空间复杂度$\mathcal{O}(1)$,前提是不使用python普通切片改为循环
74+
75+
### AC代码
76+
77+
#### C++
78+
79+
$(起点, 终点]$
80+
81+
```cpp
82+
/*
83+
* @LastEditTime: 2026-04-04 14:05:23
84+
*/
85+
class Solution {
86+
public:
87+
int minCost(vector<int>& startPos, vector<int>& homePos, vector<int>& rowCosts, vector<int>& colCosts) {
88+
int ans = 0;
89+
for (int from = startPos[0], to = homePos[0], direction = to > from ? 1 : -1; from != to; from += direction) {
90+
ans += rowCosts[from + direction];
91+
}
92+
for (int from = startPos[1], to = homePos[1], direction = to > from ? 1 : -1; from != to; from += direction) {
93+
ans += colCosts[from + direction];
94+
}
95+
return ans;
96+
}
97+
};
98+
```
99+
100+
#### Python
101+
102+
$[起点, 终点] - 起点$
103+
104+
```python
105+
'''
106+
LastEditTime: 2026-04-04 14:10:12
107+
'''
108+
from typing import List
109+
110+
class Solution:
111+
def minCost(self, startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int:
112+
sx, sy = startPos
113+
ex, ey = homePos
114+
return sum(rowCosts[min(sx, ex) : max(sx, ex) + 1]) + sum(colCosts[min(sy, ey) : max(sy, ey) + 1]) - rowCosts[sx] - colCosts[sy]
115+
```
116+
117+
python切片会拷贝不可变元素
118+
119+
```python
120+
>>> a = [1, 2, 3, 4]
121+
>>> b = a[1:3]
122+
>>> print(b)
123+
[2, 3]
124+
>>> b[0] = 0
125+
>>> print(b)
126+
[0, 3]
127+
>>> print(a)
128+
[1, 2, 3, 4]
129+
```
130+
131+
<details><summary>啥都没说系列</summary>虽说是固定走法,但其实是固定中又偏自由的走法。<br/>可先左再下,也可先下再左,也可一左一下,反正拐弯不要钱,只要别同时存在往左和往右就好了。</details>
132+
133+
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/159828365)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2026/04/04/LeetCode%202087.%E7%BD%91%E6%A0%BC%E5%9B%BE%E4%B8%AD%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%9B%9E%E5%AE%B6%E7%9A%84%E6%9C%80%E5%B0%8F%E4%BB%A3%E4%BB%B7/)~
134+
>
135+
> 千篇源码题解[已开源](https://github.com/LetMeFly666/LeetCode)

Solutions/LeetCode 3418.机器人可以获得的最大金币数.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ categories: [题解, LeetCode]
7070
<p><strong>提示:</strong></p>
7171

7272
<ul>
73-
<li><code>m == coins.length</code></li>
74-
<li><code>n == coins[i].length</code></li>
73+
<li><code>n == coins.length</code></li>
74+
<li><code>m == coins[i].length</code></li>
7575
<li><code>1 &lt;= m, n &lt;= 500</code></li>
7676
<li><code>-1000 &lt;= coins[i][j] &lt;= 1000</code></li>
7777
</ul>
@@ -127,9 +127,80 @@ public:
127127
};
128128
```
129129

130+
#### Python
131+
132+
```python
133+
'''
134+
LastEditTime: 2026-04-04 14:23:48
135+
'''
136+
from typing import List
137+
from math import inf
138+
139+
class Solution:
140+
def maximumAmount(self, coins: List[List[int]]) -> int:
141+
n, m = len(coins), len(coins[0])
142+
dp = [[[-inf for _ in range(m)] for _ in range(n)] for _ in range(3)]
143+
dp[0][0][0] = coins[0][0]
144+
dp[1][0][0] = dp[2][0][0] = max(coins[0][0], 0)
145+
146+
for i in range(n):
147+
for j in range(m):
148+
if not i and not j:
149+
continue
150+
for th in range(3):
151+
dp[th][i][j] = max(dp[th][i - 1][j] if i else -inf, dp[th][i][j - 1] if j else -inf) + coins[i][j]
152+
for th in range(1, 3):
153+
dp[th][i][j] = max(dp[th][i][j], dp[th - 1][i - 1][j] if i else -inf, dp[th - 1][i][j - 1] if j else -inf)
154+
155+
return dp[2][n - 1][m - 1]
156+
```
157+
130158
## 空间优化
131159

132-
TODO:
160+
不难发现新的一行dp只需要利用上一行的dp结果,所以我们的dp数组没必要开$n$行$m$列,只需要开$1$行$m$列就好。
161+
162+
+ 时间复杂度$O(nm)$
163+
+ 空间复杂度$O(m)$
164+
165+
### AC代码
166+
167+
#### C++
168+
169+
```cpp
170+
/*
171+
* @LastEditTime: 2026-04-04 14:39:36
172+
*/
173+
const int INF = 1e9;
174+
class Solution {
175+
public:
176+
int maximumAmount(vector<vector<int>>& coins) {
177+
int n = coins.size(), m = coins[0].size();
178+
array<vector<int>, 3> dp;
179+
dp.fill(vector<int>(m));
180+
181+
for (int i = 0; i < n; i++) {
182+
array<vector<int>, 3> nextDP;
183+
nextDP.fill(vector<int>(m));
184+
for (int j = 0; j < m; j++) {
185+
if (!i && !j) {
186+
nextDP[0][0] = coins[0][0];
187+
nextDP[1][0] = nextDP[2][0] = max(coins[0][0], 0);
188+
continue;
189+
}
190+
for (int th = 0; th < 3; th++) {
191+
nextDP[th][j] = coins[i][j] + max(i ? dp[th][j] : -INF, j ? nextDP[th][j - 1] : -INF);
192+
}
193+
for (int th = 1; th < 3; th++) {
194+
nextDP[th][j] = max(nextDP[th][j], max(i ? dp[th - 1][j] : -INF, j ? nextDP[th - 1][j - 1] : -INF));
195+
}
196+
}
197+
dp = move(nextDP);
198+
}
199+
200+
return dp[2][m - 1];
201+
}
202+
};
203+
```
133204

134205
> 同步发文于[CSDN](https://letmefly.blog.csdn.net/article/details/159780459)和我的[个人博客](https://blog.letmefly.xyz/),原创不易,转载经作者同意后请附上[原文链接](https://blog.letmefly.xyz/2026/04/02/LeetCode%203418.%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%BE%97%E7%9A%84%E6%9C%80%E5%A4%A7%E9%87%91%E5%B8%81%E6%95%B0/)~
135206
>

0 commit comments

Comments
 (0)