【bzoj 1606】 [Usaco2008 Dec]Hay For Sale 购买干草 01背包
2016-05-16 11:24
507 查看
1606: [Usaco2008 Dec]Hay For Sale 购买干草
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 978 Solved: 735
[Submit][Status][Discuss]
Description
他最多可以运回多少体积的干草呢?
Input
Output
Sample Input
7 3 //总体积为7,用3个物品来背包
2
6
5
The wagon holds 7 volumetric units; three bales are offered for sale with
volumes of 2, 6, and 5 units, respectively.
Sample Output
7 //最大可以背出来的体积
思路:01背包判断可行性;
代码:
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 978 Solved: 735
[Submit][Status][Discuss]
Description
约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每一包都有它的体积Vi(l≤Vi≤C).约翰只能整包购买,
他最多可以运回多少体积的干草呢?
Input
第1行输入C和H,之后H行一行输入一个Vi.
Output
最多的可买干草体积.
Sample Input
7 3 //总体积为7,用3个物品来背包
2
6
5
The wagon holds 7 volumetric units; three bales are offered for sale with
volumes of 2, 6, and 5 units, respectively.
Sample Output
7 //最大可以背出来的体积
思路:01背包判断可行性;
代码:
#include<stdio.h> #include<iostream> using namespace std; int f[50005]; int v[5005]; int main() { int c,h; scanf("%d%d",&c,&h); for(int i=1;i<=h;i++) scanf("%d",&v[i]); f[0]=1; for(int i=1;i<=h;i++) { for(int j=c;j>=v[i];j--) if(f[j-v[i]]==1) f[j]=1; } for(int i=c;i>=0;i--) { if(f[i]) { cout<<i<<endl; return 0; } } }
相关文章推荐
- 数据库理论基本概念
- 树状数组---Squared Permutation
- 浅谈Struts2与Webwork的不同和相同点
- UVALive - 4260 Fortune Card Game (DP&状态转移)好题
- 使用Jenkins+xcodebuild搭建iOS的持续集成系统
- 在 vSphere Distributed Switch 上编辑 VMkernel 配置
- 【iCore3 双核心板_ uC/OS-III】例程七:信号量——任务同步
- Hadoop和大数据:60款顶级开源工具
- 关于智能码控门禁系统项目的二维码验证问题
- HDU-1166- 敌兵布阵(线段树 插点问线)
- iOS代码量统计
- 添加vMotion网络的VMkernel端口组
- 让EditText不能自动获取焦点
- Android Sqlite 数据库版本更新
- Unknown system variable 'tx_read_only'
- 八大排序之插入排序
- iReport各块区域的作用
- android 中webview退出当前页面仍然继续播放的问题
- Unity3D -- ScreenToWorldPoint
- 二叉查找树详解