#include
#include
#include
using namespace std;
const int INF=0x30303030;
const int SIZE=+;
int w[SIZE];
int v[SIZE];
int dp[SIZE];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int E,F;
scanf("%d %d",&E,&F);
int vol=F-E;
int N;
scanf("%d",&N);
for(int i=;i<N;i++)
{
scanf("%d %d",&v\[i\], &w\[i\]);
}
memset(dp,INF,sizeof(dp));
dp\[\]=;
for(int i=;i<N;i++)
for(int j=w\[i\];j<=vol;j++)
if(dp\[j\]>dp\[j-w\[i\]\]+v\[i\])
dp\[j\]=dp\[j-w\[i\]\]+v\[i\];
if(dp\[vol\]==INF)
printf("This is impossible.\\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\\n",dp\[vol\]);
}
return ;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章