poj 3628 01背包问题
来源:互联网 发布:lda主题模型 python 编辑:程序博客网 时间:2024/05/16 03:24
题意: n头奶牛叠罗汉,给你个高度b,要求你找几头奶牛叠加比b高,但要求高出的值尽可能的小,问这个高出的值是多少
把奶牛的总和减去b,就是这个背包的容量,填充它,求出的最大值与背包的容量做差,结果就是他了。
#include<stdio.h>#include<string.h>int v[20000000],sum,c[100];int max(int a,int b){return a>b?a:b;}int main(){int n,b;while(scanf("%d%d",&n,&b)!=EOF){for(int i=0;i<=n;i++) v[i]=0;sum=0;for(int i=1;i<=n;i++){scanf("%d",&c[i]);sum+=c[i];}int it=sum-b;for(int i=1;i<=n;i++){for(int j=it;j>=c[i];j--){v[j]=max(v[j],v[j-c[i]]+c[i]);}}printf("%d\n",it-v[it]);}return 0;}
- poj 3628 01背包问题
- 01背包问题 poj 3624
- POJ 3624 01背包问题
- poj 3211 01背包问题
- POJ 2184 01 背包问题
- Dividing+POJ+01背包问题
- poj 3628 01背包
- poj 3628 01背包
- poj 3628 01 背包
- 简单01背包问题求解 POJ:3628 Bookshelf 2
- 动态规则 01背包问题 poj 1837 3628
- poj 3211 Washing Clothes(01背包问题)
- POJ 状态DP+ 01 背包问题
- poj 3624 最基本01背包问题
- poj 3211 Washing Clothes 01背包问题
- poj 3624 Charm Bracelet 01背包问题
- POJ 3624 Charm Bracelet 01背包问题
- 01背包问题:poj 3624 Charm Bracelet
- libjson 编译和使用 - 2. 配置使用lib文件
- 回顾:字符数据在内存中的存储形式以及其使用方法
- Btrace User Guide
- 介绍Smart Client组件网站
- Android实现解析XML文件
- poj 3628 01背包问题
- C/C++数组名与指针区别深层探索
- 小米盒子被禁-多屏互动标准Wifi Display可以解救小米之痛
- 解析后存储数据库
- ecshop如何增加产品描述编辑器
- 类型转换
- 北大ACM poj1068 Parencodings
- 真正优秀的程序员有哪些与众不同之处?
- ZOJ 3666 Alice and Bob(博弈)