AcWing 482. 合唱队形
原题链接
简单
作者:
不知名的fE
,
2024-11-18 12:52:01
,
所有人可见
,
阅读 1
import java.util.*;
public class Main {
static final int N = 110;
static int[] a = new int[N], f = new int[N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String[] s = sc.nextLine().split(" ");
for (int i = 1; i <= n; i++) a[i] = Integer.parseInt(s[i - 1]);
for (int i = 1; i <= n; i++) {
f[i] = 1;
for (int j = 1; j < i; j++)
if (a[i] > a[j]) f[i] = Math.max(f[i], f[j] + 1);
}
int res = 0;
for (int i = n; i > 0; i--) {
int t = f[i];
f[i] = 1;
for (int j = n; j > i; j--)
if (a[i] > a[j]) f[i] = Math.max(f[i], f[j] + 1);
res = Math.max(res, f[i] + t - 1);
}
System.out.println(n - res);
}
}