给出空瓶重量和当前重量,给出硬币种类个数n,给出每种硬币的价值和重量,求瓶内至少含有多少钱。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 11111
#define INF 2222222
#define ma 600
int p[ma],w[ma];
int dp[maxn];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof(dp));
memset(p,0,sizeof(p));
memset(w,0,sizeof(w));
int e,f;
scanf("%d%d",&e,&f);
int m=f-e;
//printf("%d\n",m);
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d %d",&p[i],&w[i]);
for(int j=1;j<=m;j++)
dp[j]=INF;
for(int i=1;i<=n;i++)
{
for(int j=w[i];j<=m;j++)
{
if(dp[j]>dp[j-w[i]]+p[i])
dp[j]=dp[j-w[i]]+p[i];
}
}
if(dp[m]==INF)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m]);
}
return 0;
}