-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path1065.cc
57 lines (49 loc) · 1.33 KB
/
1065.cc
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
//Name: Wooden Sticks
//Level: 3
//Category: DAG,最小パス被覆,Minimum path cover
//Note:
/*
* 3636 Nested Dollsとほぼ同じ.
* (参照: https://github.com/osak/POJ/blob/master/3636.cc)
* ただし条件に等号が入っているため,同じfirstをまとめて処理する必要はない.
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <set>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
scanf("%d", &T);
while(T--) {
int N;
scanf("%d", &N);
vector<pair<int, int> > sticks(N);
for(int i = 0; i < N; ++i) {
int a, b;
scanf("%d %d", &a, &b);
sticks[i].first = a;
sticks[i].second = b;
}
sort(sticks.begin(), sticks.end());
sticks.erase(unique(sticks.begin(), sticks.end()), sticks.end());
multiset<int> ws;
vector<pair<int,int> >::iterator it = sticks.begin();
while(it != sticks.end()) {
multiset<int>::iterator ub = ws.upper_bound(it->second);
if(ub != ws.begin()) {
--ub;
ws.erase(ub);
}
ws.insert(it->second);
++it;
}
cout << ws.size() << endl;
}
return 0;
}