题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114
AC code:
#include<bits/stdc++.h> using namespace std; int main() { int c; scanf("%d",&c); while(c--) { ],w[]; scanf("%d%d%d",&e,&f,&n); ; i<n; i++) scanf("%d%d",&p[i],&w[i]); ]; ; i<=(f-e); i++)dp[i]=; dp[]=; ; i<n; i++) for(int j=w[i]; j<=(f-e); j++) dp[j]=min(dp[j],dp[j-w[i]]+p[i]); )printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f-e]); } ; }