题目 :Problem - 1114 (hdu.edu.cn)
#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int a[510],b[510],dp[10010];
int main(){int T,E,F,H,N;scanf("%d",&T);while(T--){scanf("%d %d",&E,&F);H=F-E;scanf("%d",&N);memset(dp,INF,sizeof dp);dp[0]=0; for(int i=0;i<N;i++){scanf("%d %d",&a[i],&b[i]);}for(int i=0;i<N;i++){for(int j=b[i];j<=H;j++){dp[j]=min(dp[j],dp[j-b[i]]+a[i]);}}if(dp[H]==INF){printf("This is impossible.\n");}else{printf("The minimum amount of money in the piggy-bank is %d.\n",dp[H]);}}return 0;
}