• 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
  • 相关阅读:
    HashMap于Hashtable的区别
    redis分布式锁
    mybatis基本认识
    怎么获取硬件线程数,Future,创建线程
    查看端口号有什么在用
    javaScript 中的字符操作
    获取类里面的所有属性
    给Date赋值
    实现多人聊天
    客户端与服务器端执行报重置问题
  • 原文地址:https://www.cnblogs.com/radical/p/4009734.html
Copyright © 2020-2023  润新知