呼呼呼呼呼呼呼呼呼·······················
~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<stdio.h>
#include<string.h>#define MAX 100000000
#define min(a,b) a<b?a:b
int bb[500000];
int vv;
int main()
{
int t,a,b,v[50000],w[50000],i,n,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
scanf("%d",&n);
vv=b-a;
for(i=0;i<n;i++)
scanf("%d%d",&w[i],&v[i]);
for(i=1;i<=vv;i++)
bb[i]=MAX;
for(i=0;i<n;i++)
for(j=v[i];j<=vv;j++)
bb[j]=min(bb[j],bb[j-v[i]]+w[i]);
if(bb[vv]==MAX)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",bb[vv]);
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114