其实就是用完全背包罢了 但是我却因为数组开小了 超时了好几次
发现之后顿时感觉快崩溃了
AC:#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#define INF 0x3f3f3f3f
using namespace std;
int dp[100001];
int t, p[500005], w[100005];
int min(int x,int y)
{
return x>y?y:x;
}
int main()
{
scanf("%d",&t);
while(t--)
{
int n,E,F;
scanf("%d%d",&E,&F);
scanf("%d",&n);
F-=E;
for(int i = 1; i <= n; i++)
{
scanf("%d%d",&p[i],&w[i]);
}
for(int j = 0; j <= F; j++)
dp[j] = INF;
dp[0] = 0;
for(int i = 1; i <= n; i++)
{
for(int j = w[i]; j <= F; j++)
{
dp[j] = min(dp[j],dp[j - w[i]] + p[i]);
}
}
if(dp[F]!=INF)
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[F]);
else
printf("This is impossible.\n");
}
return 0;
}