题解 | #合唱队#

合唱队

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

import sys

def get_max_incre(this_tall):
    N = len(this_tall)
    dp=[1 for i in range(N)]
    for i in range(N):
        maxl = 1
        for j in range(i):
            if this_tall[i]>this_tall[j]:
                this_l = dp[j]+1
                if this_l>maxl:
                    maxl = this_l
        
        dp[i] = maxl
    return dp

if __name__ == "__main__": 
    N = int(input())
    for line in sys.stdin:
        tall = list(map(int,line.split()))
        tall_re = reversed(tall)
        tall_re = list(tall_re)

        l1 = get_max_incre(tall)
        l2 = get_max_incre(tall_re)
        l2.reverse()

        maxl = 0
        for i in range(N):
            if l1[i]+l2[i]>maxl:
                maxl=l1[i]+l2[i]

        print(N-(maxl-1))

全部评论

相关推荐

牛客279957775号:铁暗恋
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务