码迷,mamicode.com
首页 > 其他好文 > 详细

hdu--4502--dp

时间:2014-10-07 22:32:04      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   for   sp   

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

bubuko.com,布布扣
 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:

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

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

hdu--4502--dp

标签:style   blog   http   color   io   os   ar   for   sp   

原文地址:http://www.cnblogs.com/radical/p/4009734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!