标签:
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 5 const int inf=0x3f3f3f3f; 6 7 int main() 8 { 9 int t,E,F,i,n,j; 10 int dp[10005],p[10005],w[10005]; 11 scanf("%d",&t); 12 while(t--) 13 { 14 scanf("%d%d",&E,&F); 15 scanf("%d",&n); 16 for(i=0;i<n;i++) 17 scanf("%d%d",&p[i],&w[i]); 18 for(i=0;i<=F-E;i++) 19 dp[i]=inf; 20 dp[0]=0; 21 for(i=0;i<n;i++) 22 for(j=w[i];j<=(F-E);j++) 23 dp[j]=min(dp[j],dp[j-w[i]]+p[i]); 24 if(dp[F-E]==inf) 25 printf("This is impossible.\n"); 26 else 27 printf("The minimum amount of money in the piggy-bank is %d.\n",dp[F-E]); 28 } 29 return 0; 30 }
标签:
原文地址:http://www.cnblogs.com/homura/p/4789601.html