HDU -- 4502 -- DP

Source: Internet
Author: User

It is also acceptable for the DP question. If there is no salary, it is generally asked about the maximum number of programs that m can arrange. It is generally solved with greed.

 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:

After all, we will all live what we wanted to be together with others.

Breaking up is our dream to step out of each other.

HDU -- 4502 -- DP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.