https://vjudge.net/contest/68966#problem/F
初始化就行了;dp【0】=0;
这题还要刚好装满背包,输出时进行判断
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long using namespace std; const int N=,inf=0x3f3f3f;
int n,v[N],w[N],dp[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int a,b,n,W;
scanf("%d%d",&a,&b);
W=b-a;
memset(dp,inf,sizeof(dp));
dp[]=;
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d%d",&v[i],&w[i]);
for(int i=;i<n;i++)
for(int j=w[i];j<=W;j++)
dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
if(dp[W]>=inf)printf("This is impossible.\n");
else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[W]);
}
return ;
}