-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14002.cpp
More file actions
57 lines (43 loc) · 1.1 KB
/
14002.cpp
File metadata and controls
57 lines (43 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
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include <string>
using namespace std;
int arr[1001];
int dp[1001];
int visited[1001];
int maxroot;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int N; cin >> N;
for (int i = 0; i < N; i++) {
cin >> arr[i];
dp[i] = 1;
}
int max = 1;
for (int i = 0; i < N; i++) {
for (int prev = 0; prev < i; prev++) {
if (arr[i] > arr[prev]) {
if (dp[i] < dp[prev] + 1) {
visited[i] = prev;
dp[i] = dp[prev] + 1;
if (max < dp[i]) {
maxroot = i;
max = dp[i];
}
}
}
}
}
cout << max << '\n';
int next = maxroot;
vector<int>v;
for (int i = 0; i < max; i++) {
v.push_back(arr[maxroot]);
maxroot = visited[maxroot];
}
for (int i = v.size() - 1; i >= 0; i--) {
cout << v[i] << " ";
}
}