AcWing 1017. 怪盗基柯的滑翔翼
原题链接
简单
作者:
不知名的fE
,
2024-11-18 11:05:38
,
所有人可见
,
阅读 3
题目描述
样例
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 T = Integer.parseInt(sc.nextLine());
while (T -- > 0) {
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]);
int res = 0;
//正向上升子序列
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);
res = Math.max(res, f[i]);
}
//反向上升子序列
for (int i = n; i > 0; 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]);
}
System.out.println(res);
}
}
}