题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa?tpId=37&tqId=21326&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fdifficulty%3D3%26judgeStatus%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=3&judgeStatus=1&tags=&title=
n = int(input()) nums = list(map(int, input().split())) # 动态规划,每个数往右走的最大步数等于它右边所有数字中大于它的max【所有大于它的数字能走的步数】+1 if n == 1: print(1) else: d = [1 for i in range(n)] for i in range(n-2, -1, -1): # 最后一个肯定是1,不用考虑 temp = [] # 保存这个数右边比他大的数的步数 for j in range(i, n): if nums[j] > nums[i]: temp.append(d[j]) if not temp: # 没有比他大的数 continue else: d[i] = max(temp) + 1 print(max(d))