题目描述
python解
py版
import sys
gird = []
for line in sys.stdin:
gird.append((line.split()))
n = int((gird.pop(0))[0])
nums = [int(i) for i in gird[0]]
# 题解
dp_left = [1]*(len(nums))
dp_right = [1]*(len(nums))
#从左边开始
for i in range(len(nums)):
for j in range(i):
if nums[i] > nums[j]:
dp_left[i] = max(dp_left[i],dp_left[j]+1)
# print(dp_left)
nums_r = nums[::-1]
#从右边开始
for i in range(len(nums_r)):
for j in range(i):
if nums_r[i] > nums_r[j]:
dp_right[i] = max(dp_right[i],dp_right[j]+1)
dp_right = dp_right[::-1]
# print(dp_right)
res = 0
for i in range(len(nums)):
res = max(res,dp_left[i] + dp_right[i]-1)
print(res)