标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<string.h> #define INF 0x7ffffff #define MAXN 10000 int dp[MAXN+10];//dp[i]表容量为i的时候所装东西的最小价值 int main() { int w1,w2; int P,W; int T,n; int i,j; scanf("%d",&T); while(T--) { scanf("%d%d",&w1,&w2); scanf("%d",&n); for(i=1;i<=w2-w1;i++) dp[i]=INF;//初始化为无穷大 dp[0]=0; while(n--) { scanf("%d%d",&P,&W); for(i=W;i<=w2-w1;i++) if(dp[i]>dp[i-W]+P) dp[i]=dp[i-W]+P; } if(dp[w2-w1]==INF) printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[w2-w1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/rain-1/p/4758705.html