题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
int t,dp[10005];
scanf("%d",&t);
while(t--)
{
int e,f;
scanf("%d%d",&e,&f);
int n,p[50005],value[50005],weight[10005];
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%d%d",&value[i],&weight[i]);
int v=f-e;
dp[0]=0;
for(int i=1; i<=v; i++)
dp[i]=INF;
for(int i=0; i<n; i++)
for(int j=weight[i]; j<=v; j++)
dp[j]=min(dp[j],dp[j-weight[i]]+value[i]);
if(dp[v]==INF)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[v]);
}
return 0;
}