Skip to content

Commit

Permalink
fix python bug - basic_lis
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouTimeMachine committed Jun 17, 2024
1 parent 13d133d commit 624bc08
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/courses/python/hw.md
Original file line number Diff line number Diff line change
Expand Up @@ -2335,13 +2335,13 @@ print(basic_lis(L))
```

??? general "Answer"
`6`
`7`

这个程序实现了最长递增子序列 (Longest Increasing Subsequence, LIS) 问题的动态规划算法。`l` 是一个列表,`l[i]` 表示以 `seq[i]` 结尾的最长递增子序列的长度。

算法的基本思想是,对于每个元素 `seq[cur]`,`l[cur]` 的基本值是 1,对于所有比 `cur` 小的 `pre`,如果 `seq[pre] < seq[cur]`,那么到 `pre` 为止的递增子序列就可以在后面接上一个 `seq[cur]`,于是出现新的递增子序列长度 `1+l[pre]`。遍历之前的元素 `seq[pre]`,找到最大的满足 `seq[pre] < seq[cur]` 的 `1+l[pre]`,就是 `l[cur]` 的值。

对于输入 `L`,最长递增子序列是 `[49, 64, 66, 68, 87, 96]`,长度为 6
对于输入 `L`,最长递增子序列是 `[49, 64, 66, 68, 87, 96, 99]`,长度为 7

**Q15-4-5.** 下面程序用动态规划法快速计算斐波那契数,在下划线处填上正确的表达式。

Expand Down

0 comments on commit 624bc08

Please sign in to comment.