hdu--4502--dp

还可以接受的dp题 如果没有那个工资的话 一般是问到m可以安排的最多节目数 一般是用贪心解决的

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 const int size = 110;
 7 struct node
 8 {
 9     int st;
10     int end;
11     int price;
12 }data[size*10];
13 int dp[size];
14 bool cmp( const node a , const node b )
15 {
16     return a.end < b.end;
17 }
18 
19 int main()
20 {
21     cin.sync_with_stdio(false);
22     int t , n , m , cnt;
23     int a , b , c;
24     cin >> t;
25     while(t--)
26     {
27         cin >> m >> n;
28         cnt = 0;
29         memset( dp , 0 , sizeof(dp) );
30         for( int i = 0 ; i<n ; i++ )
31         {
32             cin >> a >> b >> c;
33             if( a<=m && b<=m )
34             {
35                 data[cnt].st = a;
36                 data[cnt].end = b;
37                 data[cnt++].price = c;
38             }
39         }
40         sort( data , data+cnt , cmp );
41         for( int i = 0 ; i<cnt ; i++ )
42         {
43             for( int j = m ; j>=data[i].end ; j-- )
44             {
45                 dp[j] = max( dp[j] , dp[ data[i].st-1 ] + data[i].price );
46             }
47         }
48         cout << dp[m] << endl;
49     }
50     return 0;
51 }
View Code

today:

  我们终究都会和别人过上本来我们本来想要一起过的生活

  分手是我们一步步走出彼此的梦  

just follow your heart
原文地址:https://www.cnblogs.com/radical/p/4009734.html