标签:
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1114
1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 5 int dp[10005]; 6 int wb, wf, wc; 7 int n; 8 int p[505], w[505]; 9 10 int main(){ 11 ios::sync_with_stdio( false ); 12 13 int T; 14 cin >> T; 15 while( T-- ){ 16 memset( dp, 0x3f3f3f3f, sizeof( dp ) ); 17 dp[0] = 0; 18 19 cin >> wb >> wf; 20 wc = wf - wb; 21 22 cin >> n; 23 for( int i = 1; i <= n; i++ ) 24 cin >> p[i] >> w[i]; 25 26 for( int i = 1; i <= n; i++ ) 27 for( int j = w[i]; j <= wc; j++ ) 28 if( dp[j] > dp[j - w[i]] + p[i] ) 29 dp[j] = dp[j - w[i]] + p[i]; 30 31 if( dp[wc] == 0x3f3f3f3f ) cout << "This is impossible.\n"; 32 else cout << "The minimum amount of money in the piggy-bank is " << dp[wc] << ".\n"; 33 } 34 35 return 0; 36 }
标签:
原文地址:http://www.cnblogs.com/hollowstory/p/5366217.html