标签:
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2191
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 5 class node{ 6 public: 7 int p, h, c; 8 }rice[105]; 9 int n, m; 10 int dp[105]; 11 12 int main(){ 13 ios::sync_with_stdio( false ); 14 15 int C; 16 cin >> C; 17 while( C-- ){ 18 memset( dp, 0, sizeof( dp ) ); 19 20 cin >> n >> m; 21 22 for( int i = 1; i <= m; i++ ) 23 cin >> rice[i].p >> rice[i].h >> rice[i].c; 24 25 for( int i = 1; i <= m; i++ ){ 26 int p = 1; 27 while( p < rice[i].c ){ 28 for( int j = n; j >= rice[i].p * p; j-- ) 29 if( dp[j] < dp[j - rice[i].p * p] + rice[i].h * p) 30 dp[j] = dp[j - rice[i].p * p] + rice[i].h * p; 31 32 rice[i].c -= p; 33 p <<= 1; 34 } 35 36 for( int j = n; j >= rice[i].p * rice[i].c; j-- ) 37 if( dp[j] < dp[j - rice[i].p * rice[i].c] + rice[i].h * rice[i].c ) 38 dp[j] = dp[j - rice[i].p * rice[i].c] + rice[i].h * rice[i].c; 39 } 40 41 cout << dp[n] << endl; 42 } 43 return 0; 44 }
HDU-2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 ( 多重背包 )
标签:
原文地址:http://www.cnblogs.com/hollowstory/p/5364890.html