-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuva-10131.cpp
58 lines (45 loc) · 1.25 KB
/
uva-10131.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//uva 10131
//Is Bigger Smarter?
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
int main(void)
{
vector <pair <pair <int, int>, int> > elephant;
int w, iq;
int n = 0;
while (cin >> w >> iq)
elephant.push_back(make_pair(make_pair(w, iq), n++));
sort(elephant.begin(), elephant.end());
vector <int> lis(elephant.size(), 1);
vector <int> pre(elephant.size(), -1);
for (int i = 1; i < elephant.size(); ++i){
int wi = elephant[i].first.first;
int iqi = elephant[i].first.second;
for (int j = 0; j < i; ++j){
int wj = elephant[j].first.first;
int iqj = elephant[j].first.second;
if (wj < wi && iqi < iqj && lis[i] < lis[j] + 1){
lis[i] = lis[j] + 1;
pre[i] = j;
}
}
}
int index = 0;
for (int i = 0; i < elephant.size(); ++i)
if (lis[index] < lis[i])
index = i;
stack <int> result;
while (index >= 0){
result.push(index);
index = pre[index];
}
cout << result.size() << endl;
while (!result.empty()){
cout << elephant[result.top()].second + 1 << endl;
result.pop();
}
return 0;
}