-
Notifications
You must be signed in to change notification settings - Fork 0
/
1214 线段覆盖.cpp
61 lines (56 loc) · 1.03 KB
/
1214 线段覆盖.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
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
struct line
{
int start;
int fin;
};
vector<line> total;
bool operator < (const line &a1,const line &a2)
{
return a1.start < a2.start;
}
int main(void)
{
int n;
line tmp;
int dp[102] = {0};
cin >> n;
for (int i = 0;i < n;i++)
{
cin >> tmp.start;
cin >> tmp.fin;
if (tmp.start > tmp.fin)
{
int p = tmp.start;
tmp.start = tmp.fin;
tmp.fin = p;
}
total.push_back(tmp);
}
sort(total.begin(),total.end());
dp[0] = 1;
for (int i = 1;i < n;i ++)
{
int sum = 0;
for (int j = i - 1;j >= 0;j --)
{
if (total[j].fin <= total[i].start)
{
sum = dp[j];
break;
}
}
dp[i] = sum + 1;
}
int max = 0;
for (int i = 0;i < n;i++)
{
if (dp[i] > max)
max = dp[i];
}
cout << max << endl;
return 0;
}