-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_14002.cpp
More file actions
60 lines (50 loc) · 1.1 KB
/
bj_14002.cpp
File metadata and controls
60 lines (50 loc) · 1.1 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
60
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
int main() {
int N;
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> N;
long long permu[1000001] = {};
for(int i = 0; i<N; i++) {
cin >> permu[i];
}
long long dp[1000001] = {};
long long max = 0;
for(int i = 0; i<N; i++) {
dp[i] = 1;
for(int j = 0; j<i; j++) {
if(permu[i] > permu[j] && dp[j]+1 > dp[i] ) {
dp[i] = dp[j] + 1;
if(max < dp[i])
max = dp[i];
}
}
}
stack<int> S;
for(int i = N-1; i>= 0; i--) {
if(max == dp[i]) {
S.push(permu[i]);
max--;
}
if(max == 0) {
break;
}
}
if(S.size() == 0) {
cout << 1 << "\n";
cout << permu[0] << "\n";
return 0;
}
else
cout << S.size() << "\n";
long long siz = S.size();
for(long long i = 0; i<siz; i++) {
cout << S.top() << ' ';
S.pop();
}
}