当前位置: 代码迷 >> 综合 >> HDU 1114 Piggy-Bank 完全背包 .
  详细解决方案

HDU 1114 Piggy-Bank 完全背包 .

热度:93   发布时间:2023-09-23 06:34:13.0

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1114

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=10000+5;
const int INF=0x3f3f3f3f;
int d[maxn];
int main()
{int T,lW,NW,W,n,v,w; cin>>T;while(T--){cin>>lW>>NW;W=NW-lW;cin>>n;memset(d,INF,sizeof(d));d[0]=0;for(int i=1;i<=n;i++){scanf("%d%d",&v,&w);if(w>W) continue;for(int j=w;j<=W;j++)d[j]=min(d[j],d[j-w]+v);}if(d[W]==INF) cout<<"This is impossible."<<endl;else printf("The minimum amount of money in the piggy-bank is %d.\n",d[W]);}return 0;
}


  相关解决方案