AcWing 895. 最长上升子序列
原题链接
简单
作者:
dsf2
,
2021-03-04 08:28:44
,
所有人可见
,
阅读 295
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i] = sc.nextInt();
int res = 0;
int[] dp = new int[n + 1];
for (int r = 0; r < n; r++) {
dp[r] = 1;
int max = 0;
for (int l = r; l >= 0; l--) {
if (arr[l] < arr[r])
max = Math.max(max, dp[l]);
}
dp[r] += max;
res = Math.max(res, dp[r]);
}
System.out.println(res);
}
}