标签:
#include<stdio.h> #include<string.h> #include<math.h> #define INF 0xfffffff #define N 20000 int main() { int T,w1,w2,n,p,k,dp[N],w,i,j; scanf("%d",&T); while(T--) { scanf("%d%d",&w1,&w2); w=w2-w1; scanf("%d",&n); for(i=1;i<=w;i++) { dp[i]=INF; } dp[0]=0; for(i=0;i<n;i++) { scanf("%d %d",&p,&k); for(j=k;j<=w;j++) { if(dp[j]>dp[j-k]+p) dp[j]=dp[j-k]+p; } } if(dp[w]==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/linliu/p/4463179.html