暑期dp46道(17)--HDOJ1114 Piggy Bank 完全背包
来源:互联网 发布:国外windows优化软件 编辑:程序博客网 时间:2024/03/29 02:57
题目链接:HDOJ 1114
这题提议很好理解,就是给定coins的weight和不同种类的coins,求组合成这个weight最小的价值,若不能组合,输出"This is impossible.";
题解:裸完全背包问题。不过是求装满背包而且要最小,所以还不算太裸;(max->min)
dp[0] = 0;其他初始化最大值,判断dp[weight];若为初始值则无法组合,否则就输出。
代码:
#include<cstdio>#include<cstring>#include<string>#include<algorithm>#define debug 0#define Min(a,b) ((a<b)?a:b)#define INF 0x3fffffff using namespace std;const int maxn = 10000+5;int c[505],w[505],v,n;int dp[maxn];int main(){#if debugfreopen("in.txt","r",stdin);#endif//debug int T,a,b; scanf("%d",&T); while(T--){ scanf("%d%d",&a,&b); v = b - a; for(int i = 0;i <= v;i++) dp[i] = INF; dp[0] = 0; scanf("%d",&n); for(int i = 1;i <= n;i++) scanf("%d%d",&w[i],&c[i]); for(int i = 1;i <= n;i++) for(int j = c[i];j <= v;j++) dp[j] = min(dp[j],dp[j-c[i]] + w[i]);//完全背包 if(dp[v] == INF) printf("This is impossible.\n"); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[v]); } return 0;}
0 0
- 暑期dp46道(17)--HDOJ1114 Piggy Bank 完全背包
- HDOJ1114 Piggy-Bank[完全背包]
- Piggy-Bank(完全背包)
- Piggy-Bank(完全背包)
- Piggy-Bank(完全背包)
- Piggy-Bank(完全背包)
- Piggy-Bank(完全背包)
- Piggy-Bank (完全背包)
- Piggy-Bank (完全背包)
- 完全背包- Piggy-Bank
- Piggy-Bank(完全背包)
- 完全背包,piggy-bank
- Piggy-Bank (完全背包)
- Piggy-Bank完全背包
- 【完全背包】Piggy - Bank
- Piggy-Bank(完全背包)
- (完全背包)Piggy-Bank(P1384)
- POJ 1384 Piggy-Bank (完全背包)
- jenkins 可以使用的环境变量
- Codeforces Round #364 (Div. 2) C
- 【其它】医院百科
- 阿里云服务器centos6.5 配置
- 【其它】Coder专属的15个谜语 你能猜中几个?
- 暑期dp46道(17)--HDOJ1114 Piggy Bank 完全背包
- 【iOS开发】用户点击频繁,多个异步网络请求取消问题?
- HDU 1002 A + B Problem II
- 华为OJ——字符个数统计
- 多校赛第7场 hdu5818 Joint Stacks 双向链表
- 【iOS开发】UITableView 默认选择某行的方法
- Android之微信第三方登录
- C\C++中istringstream、ostringstream、stringstream 类介绍 .
- Python的编码注释# -*- coding:utf-8 -*-