题解 | #合唱队#
合唱队
https://www.nowcoder.com/practice/6d9d69e3898f45169a441632b325c7b4
n = int(input()) height = list(map(int,input().split())) def cacu_left(h): dp = [1]*n # dp[i]指的是第i个人左边符合合唱队的人 for i in range(len(h)): for j in range(i): if h[j] < h[i] and dp[i] < dp[j] + 1: # 动态规划,先局部最优再全局最优 dp[i] = dp[j] + 1 return dp left_nums = cacu_left(height) right_nums = cacu_left(height[::-1])[::-1] for i in range(n): left_nums[i] = left_nums[i] + right_nums[i] -1 # 思路是求剩下多少人,再用原来的人数减去剩下的人数 print(n - max(left_nums))