题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
import bisect def inc_max(l): dp = [1]*len(l) # 初始化dp,最小递增子序列长度为1 arr = [l[0]] # 创建数组 for i in range(1,len(l)): # 从原序列第二个元素开始遍历 if l[i] > arr[-1]: arr.append(l[i]) dp[i] = len(arr) else: pos = bisect.bisect_left(arr, l[i]) # 用二分法找到arr中第一个比ele_i大(或相等)的元素的位置 arr[pos] = l[i] dp[i] = pos+1 return dp while 1: try: num=int(input()) ls=list(map(int,input().split())) max_step=0 for index in range(len(ls)): dp=inc_max(ls[index:]) #print(dp) temp=0 for i in dp: if i>temp: temp=i if temp>max_step: max_step=temp print(max_step) except: break