最长递增子序列长度

#coding=utf-8
import sys
n = int(input())
nums = [int(x) for x in input().split()]

'''
dp[i]以nums[i]结尾的最长递增子序列长度
if nums[i]>nums[j]说明nums[i]能加到nums[j]后面
dp[i+1]=max(dp[i+1],dp[j]+1)
'''

def length_of_list(nums):
l = len(nums)
if l == 0:
return
dp = [1]*l
for i in range(l-1):
for j in range(i+1):
if nums[i+1]>nums[i]:
dp[i+1] = max(dp[i],dp[j]+1)
return max(dp)
t = length_of_list(nums)
print(t)

posted on 2020-03-16 17:02  limingqi  阅读(241)  评论(0编辑  收藏  举报

导航