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