AcWing 1016. 最大上升子序列
原题链接
简单
作者:
不知名的fE
,
2024-11-18 18:56:47
,
所有人可见
,
阅读 1
import java.util.*;
public class Main {
static final int N = 1010;
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]);
int ans = 0;
for (int i = 1; i <= n; i++) {
f[i] = a[i];//可能本身就是最大:a[i]=无穷大 当下面计算结果不会比a[i],则更新为a[i]
for (int j = 1; j < i; j++)
if (a[i] > a[j]) f[i] = Math.max(f[i], f[j] + a[i]);
ans = Math.max(f[i], ans);
}
System.out.println(ans);
}
}