File tree 1 file changed +5
-5
lines changed
Contents/10.Dynamic-Programming/03.Linear-DP
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -588,7 +588,7 @@ class Solution:
588
588
589
589
###### 2. 定义状态
590
590
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$ 个元素结尾的子数组 」的最长公共子数组长度。
592
592
593
593
###### 3. 状态转移方程
594
594
@@ -597,12 +597,12 @@ class Solution:
597
597
598
598
###### 4. 初始条件
599
599
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$。
602
602
603
603
###### 5. 最终结果
604
604
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 ] $ 中最大值即为答案。
606
606
607
607
##### 思路 1:代码
608
608
@@ -742,4 +742,4 @@ class Solution:
742
742
## 参考资料
743
743
744
744
- 【书籍】算法竞赛进阶指南
745
- - 【文章】[ 动态规划概念和基础线性DP | 潮汐朝夕] ( https://chengzhaoxi.xyz/1a4a2483.html )
745
+ - 【文章】[ 动态规划概念和基础线性DP | 潮汐朝夕] ( https://chengzhaoxi.xyz/1a4a2483.html )
You can’t perform that action at this time.
0 commit comments