完全背包 基础题:http://acm.hdu.edu.cn/showproblem.php?pid=1114
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
#define N 505
#define INF 25000005
int weight[N],price[N];
int dp[N*20];
int main(){
int T;scanf("%d",&T);
while(T--){
memset(dp,INF,sizeof(dp));
dp[0]=0;
int E,F;scanf("%d%d",&E,&F);
int W=F-E;
int n;scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d%d",&price[i],&weight[i]);
for(int i=0;i<n;i++)
for(int j=weight[i];j<=W;j++)
dp[j]=min(dp[j],dp[j-weight[i]]+price[i]);
if(dp[W]<INF) printf("The minimum amount of money in the piggy-bank is %d.\n",dp[W]);
else printf("This is impossible.\n");
}//while
return 0;
}//main