AcWing 895. 最长上升子序列
原题链接
简单
作者:
Douyi
,
2020-09-24 15:37:32
,
所有人可见
,
阅读 351
import java.util.Scanner;
public class Main {
static int N = 1010;
static int[] f = new int[N];
static int[] a = new int[N];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i ++ )
a[i] = sc.nextInt();
int max = 0;//记录最大值
for (int i = 1; i <= n; i ++) {
f[i] = 1; //找不到则为1
for (int j = 1 ; j < i; j ++) {
if (a[j] < a[i]) f[i] = Math.max(f[i], f[j] + 1);
}
max = Math.max(max, f[i]); //得到数组中的最大值
}
System.out.println(max);
}
}