最长递增子序列返回子序列代码
时间: 2023-11-12 17:10:26 浏览: 70
Rust中最长递增子序列算法_rust_代码_下载
以下是最长递增子序列返回子序列的 Python 代码:
```
def LIS(nums):
n = len(nums)
dp = [1] * n
for i in range(1, n):
for j in range(i):
if nums[i] > nums[j]:
dp[i] = max(dp[i], dp[j] + 1)
max_len = max(dp)
end = dp.index(max_len)
res = [nums[end]]
for i in range(end - 1, -1, -1):
if nums[i] < nums[end] and dp[i] == dp[end] - 1:
res.append(nums[i])
end = i
return res[::-1]
```
阅读全文