HDU 1114

来源:互联网 发布:盟拓软件 编辑:程序博客网 时间:2024/06/05 04:29

http://acm.hdu.edu.cn/showproblem.php?pid=1114

#include <bits/stdc++.h>#define maxs 202020#define mme(i,j) memset(i,j,sizeof(i))using namespace std;int w[maxs],h[maxs];int dp[maxs];int main(){    int t,e,f;    scanf("%d",&t);    while(t--){        scanf("%d%d",&e,&f);        f= f-e;        int n;        scanf("%d",&n);        for(int i=0;i<n;i++)            scanf("%d%d",&w[i],&h[i]);        for(int i=0 ;i<=f ;i++) dp[i] = maxs;        dp[0]=0;        for(int i=0;i<n;i++){            for(int j=h[i];j<=f;j++){                dp[j] = min(dp[j],dp[j-h[i]]+w[i]);            }        }        if(dp[f]==maxs)            puts("This is impossible");        else            printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f]);    }    return 0;}