考虑一下, 当前类为f[i], 那我考虑前面i-1个数, 枚举1.....i-1.
如果ai > aj 就考虑更新 f[i] 看看是否能更新
import java.io.*;
import java.util.*;
class Reader {
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer tokenizer = new StringTokenizer("");
static String nextLine() throws IOException {// 读取下一行字符串
return reader.readLine();
}
static String next() throws IOException {// 读取下一个字符串
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {// 读取下一个int型数值
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {// 读取下一个double型数值
return Double.parseDouble(next());
}
}
public class Main {
final int N = 1010;
int[] f = new int[N];
int[] a = new int[N];
public void init() throws Exception {
int n = Reader.nextInt();
for (int i = 1; i <= n; i++){
a[i] = Reader.nextInt();
f[i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i-1 ; j++) {
if (a[j] < a[i]) f[i] = Math.max(f[i], f[j]+1);
}
}
int res = 0;
for (int i = 1; i <= n; i++) res = Math.max(res, f[i]);
System.out.println(res);
}
public static void main(String[] args) throws Exception {
new Main().init();
}
}