-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp11053.java
More file actions
42 lines (35 loc) · 1.05 KB
/
p11053.java
File metadata and controls
42 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
import java.util.StringTokenizer;
public class p11053 {
static int N, max_len, arr[];
static Integer dp[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
arr = new int[N];
dp = new Integer[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
for (int i = 0; i < N; i++) {
recur(i);
}
int max = dp[0];
for (int i = 1; i < N; i++) {
max = Math.max(max, recur(i));
}
System.out.println(max);
}
static int recur(int n) {
if (dp[n] == null) {
dp[n] = 1;
for (int i = n-1; i >= 0; i--) {
if (arr[i] < arr[n]) {
dp[n] = Math.max(dp[n], recur(i) + 1);
}
}
}
return dp[n];
}
}