标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10830 | Accepted: 5275 |
Description
Input
Output
Sample Input
3 10 110 2 1 1 30 50 10 110 2 1 1 50 30 1 6 2 10 3 20 4
Sample Output
The minimum amount of money in the piggy-bank is 60. The minimum amount of money in the piggy-bank is 100. This is impossible.
Source
1 //176K 94MS C++ 650B 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 #define M -0x7fffffff 7 int dp[10005]; 8 int p[505],w[505]; 9 int main(void) 10 { 11 int cas,e,f,n; 12 scanf("%d",&cas); 13 while(cas--){ 14 scanf("%d%d",&e,&f); 15 scanf("%d",&n); 16 for(int i=0;i<n;i++){ 17 scanf("%d%d",&p[i],&w[i]); 18 } 19 20 for(int i=1;i<=f;i++){ 21 dp[i] = M; 22 } 23 dp[0] = 0; 24 for(int i=0;i<n;i++){ 25 for(int j=w[i];j<=f-e;j++){ 26 if(dp[j-w[i]] != M) 27 dp[j] = max(dp[j], dp[j-w[i]] - p[i]); 28 } 29 } 30 if(dp[f-e]==M){ 31 puts("This is impossible."); 32 }else{ 33 printf("The minimum amount of money in the piggy-bank is %d.\n", -dp[f-e]); 34 } 35 } 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/GO-NO-1/p/5977674.html