-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUVA00497.cpp
38 lines (37 loc) · 970 Bytes
/
UVA00497.cpp
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
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main() {
int N;
cin >> N;
string s;
getline(cin, s);
getline(cin, s);
vector<int> v;
while (N--) {
v.clear();
while (getline(cin, s) && s != "") v.push_back(atoi(s.c_str()));
vector<int> tam(v.size(), 1), prev(v.size(), -1);
int best = 0;
for (int i = 1; i < v.size(); i++) {
for (int j = 0; j < i; j++) {
if (v[j] < v[i] && tam[j] + 1 > tam[i])
prev[i] = j, tam[i] = tam[j] + 1;
}
if (tam[best] < tam[i]) best = i;
}
printf("Max hits: %d\n", tam[best]);
stack<int> st;
do {
st.push(v[best]);
best = prev[best];
} while (best != -1);
while (!st.empty()) {
printf("%d\n", st.top());
st.pop();
}
if (N) printf("\n");
}
return 0;
}