-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_14002
More file actions
59 lines (46 loc) · 1.23 KB
/
BAEKJOON_14002
File metadata and controls
59 lines (46 loc) · 1.23 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
static int[] A;
static int[] D;
static int[] V;
public static void go(int p){
if(p==-1)return;
go(V[p]);
System.out.print(A[p] + " ");
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
A = new int[N];
D = new int[N];
V = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++){
A[i] = Integer.parseInt(st.nextToken());
}
for(int i=0; i<N; i++){
D[i]=1;
V[i]=-1;
for(int j=0; j<i; j++){
if (A[j] < A[i] && D[i] < D[j] + 1) {
D[i] = D[j]+1;
V[i]=j;
}
}
}
int max = D[0];
int p = 0;
for(int i=0; i<N; i++){
if (max < D[i]) {
max = D[i];
p = i;
}
}
System.out.println(max);
go(p);
System.out.println();
br.close();
}
}