Skip to content

Commit cbcaba0

Browse files
authored
Merge pull request #122 from kukayiyi/main
修改动态规划-线性动态规划-线性dp规划(一)中最长重复子数组条件描述
2 parents bdf258d + 68a23b7 commit cbcaba0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Contents/10.Dynamic-Programming/03.Linear-DP/01.Linear-DP-01.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ class Solution:
588588

589589
###### 2. 定义状态
590590

591-
定义状态 $dp[i][j]$ 为:「 $nums1$ 中前 $i$ 个元素为子数组($nums1[0]...nums2[i - 1]$)」和「 $nums2$ 中前 $j$ 个元素为子数组($nums2[0]...nums2[j - 1]$)」的最长公共子数组长度。
591+
定义状态 $dp[i][j]$ 为:「 $nums1$ 中以第 $i - 1$ 个元素结尾的子数组 」和「 $nums2$ 中以第 $j - 1$ 个元素结尾的子数组 」的最长公共子数组长度。
592592

593593
###### 3. 状态转移方程
594594

@@ -597,12 +597,12 @@ class Solution:
597597

598598
###### 4. 初始条件
599599

600-
- 当 $i = 0$ 时,$nums1[0]...nums1[i - 1]$ 表示的是空数组,空数组与 $nums2[0]...nums2[j - 1]$ 的最长公共子序列长度为 $0$,即 $dp[0][j] = 0$。
601-
- 当 $j = 0$ 时,$nums2[0]...nums2[j - 1]$ 表示的是空数组,空数组与 $nums1[0]...nums1[i - 1]$ 的最长公共子序列长度为 $0$,即 $dp[i][0] = 0$。
600+
- 当 $i = 0$ 时,$nums1[0]...nums1[i - 1]$ 表示的是空数组,空数组与 $nums2$ 中任意子数组的最长公共子序列长度为 $0$,即 $dp[0][j] = 0$。
601+
- 当 $j = 0$ 时,$nums2[0]...nums2[j - 1]$ 表示的是空数组,空数组与 $nums1$ 中任意子数组的最长公共子序列长度为 $0$,即 $dp[i][0] = 0$。
602602

603603
###### 5. 最终结果
604604

605-
- 根据状态定义, $dp[i][j]$ 为:「 $nums1$ 中前 $i$ 个元素为子数组($nums1[0]...nums2[i - 1]$)」和「 $nums2$ 中前 $j$ 个元素为子数组($nums2[0]...nums2[j - 1]$)」的最长公共子数组长度。在遍历过程中,我们可以使用 $res$ 记录下所有 $dp[i][j]$ 中最大值即为答案。
605+
- 根据状态定义, $dp[i][j]$ 为:「 $nums1$ 中以第 $i - 1$ 个元素结尾的子数组 」和「 $nums2$ 中以第 $j - 1$ 个元素结尾的子数组 」的最长公共子数组长度。在遍历过程中,我们可以使用 $res$ 记录下所有 $dp[i][j]$ 中最大值即为答案。
606606

607607
##### 思路 1:代码
608608

@@ -742,4 +742,4 @@ class Solution:
742742
## 参考资料
743743

744744
- 【书籍】算法竞赛进阶指南
745-
- 【文章】[动态规划概念和基础线性DP | 潮汐朝夕](https://chengzhaoxi.xyz/1a4a2483.html)
745+
- 【文章】[动态规划概念和基础线性DP | 潮汐朝夕](https://chengzhaoxi.xyz/1a4a2483.html)

0 commit comments

Comments
 (0)