-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3027.cpp
67 lines (56 loc) · 855 Bytes
/
3027.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
/*
题目:p3027 线段覆盖 2
*/
// dp[i] 表示以第i个线段结尾的最大价值
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct{
int ai;
int bi;
int ci;
} edge;
bool cmp(edge l1, edge l2)
{
if(l1.bi<=l2.bi)
return true;
return false;
}
int MaxValue(vector<edge> v)
{
int n = v.size();
sort(v.begin(),v.end(),cmp);
int dp[n];
int max_value = 0;
for(int i=0;i<n;i++)
{
dp[i] = v[i].ci;
for(int j=0;j<i;j++)
{
if(v[j].bi<=v[i].ai&&dp[j]+v[i].ci>dp[i])
dp[i] = dp[j]+v[i].ci;
}
if(dp[i]>max_value)
max_value = dp[i];
}
return max_value;
}
int main()
{
int n;
cin >> n;
int a, b, c;
edge temp;
vector<edge> v;
while(n-->0&&cin>>a>>b>>c)
{
temp.ai = a;
temp.bi = b;
temp.ci = c;
v.push_back(temp);
}
cout << MaxValue(v) << endl;
return 0;
}