hdu1114(完全背包)

来源:互联网 发布:刺客信条3低配优化 编辑:程序博客网 时间:2024/04/29 04:27

完全背包 基础题: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 25000005int 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


0 0
原创粉丝点击