-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10131.cpp
114 lines (87 loc) · 2.23 KB
/
uva10131.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
//#include <unordered_map>
using namespace std;
typedef pair<int, int> ii;
#define traverse(c, it) \
for (map<ii, int>::iterator it = c.begin(); it != c.end(); it++)
vector<int> weight;
vector<int> iq;
vector<int> parent;
vector<pair<ii, int> > desIq;
vector<int> lis;
bool cmp(pair<ii, int> elephant1, pair<ii, int> elephant2) {
if(elephant1.first.second >= elephant2.first.second) {
return true;
}
return false;
}
void computeLis() {
lis.clear();
lis.resize(weight.size(), 1);
parent.clear();
parent.resize(weight.size(), -1);
for(int i = 0; i < weight.size(); i++) {
for(int j = i+1; j < weight.size(); j++) {
pair<ii, int> elephant1 = desIq[i];
pair<ii, int> elephant2 = desIq[j];
if(elephant1.first.second > elephant2.first.second) {
if(elephant1.first.first < elephant2.first.first) {
if(1 + lis[i] > lis[j]) {
lis[j] = 1 + lis[i];
parent[j] = i;
}
}
}
}
}
int bestLis = INT_MIN;
int end = -1;
for(int i = 0; i < weight.size(); i++) {
if(lis[i] > bestLis) {
bestLis = lis[i];
end = i;
}
}
cout << bestLis << endl;
vector<int> path;
int index = end;
while(index != -1) {
path.push_back(index);
index = parent[index];
}
reverse(path.begin(), path.end());
for(int i = 0; i < path.size(); i++) {
cout << desIq[path[i]].second + 1 << endl;
}
}
int main() {
int w, intell;
weight.clear();
iq.clear();
while(true) {
cin >> w >> intell;
if(cin.eof()) {
break;
}
weight.push_back(w);
iq.push_back(intell);
}
desIq.clear();
for(int i = 0; i < weight.size(); i++) {
desIq.push_back(make_pair(make_pair(weight[i], iq[i]), i));
}
sort(desIq.begin(), desIq.end(), cmp);
computeLis();
return 0;
}