题解 | #合唱队#

合唱队

https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4

N = int(input())
ls = list(map(int,input().split()))
ls1 = [1] * len(ls)
ls2 = [1] * len(ls)

# 合唱队遍历的一定是位置
#左
for i in range(len(ls)-1):
    for j in range(i+1):
        if ls[i] > ls[j] and ls1[i] < ls1[j]+1:
            ls1[i] = ls1[j]+1

# 右
for i in range(len(ls)-1,-1,-1):
    for k in range(len(ls)-1,i-1,-1):
        if ls[i] > ls[k] and ls2[i] < ls2[k]+1:
            ls2[i] = ls2[k]+1

p = 0
for i in range(N):
    if ls1[i]+ls2[i]-1 > p:
        p = ls1[i]+ls2[i]-1

print(N-p)


全部评论

相关推荐

09-21 23:16
门头沟学院 Java
传奇逃兵王:招不起就别招,叽里咕噜说啥呢
点赞 评论 收藏
分享
永泽one:好厉害,acm➕开源,感觉找个大厂实习背书就好了,能教教开源的一些方法嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务