bzo1606: [Usaco2008 Dec]Hay For Sale 购买干草
1606: [Usaco2008 Dec]Hay For Sale 购买干草
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 1338 Solved: 991
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
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
HINT
Buying the two smaller bales fills the wagon.
Source
题解
背包可行性问题的板子(我太弱啦!
/**************************************************************
Problem: 1606
User: a799091501
Language: C++
Result: Accepted
Time:292 ms
Memory:1608 kb
****************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define N 100001
using
namespace
std;
inline
int
read()
{
int
f=1,x=0;
char
ch=
getchar
();
while
(ch>
'9'
|ch<
'0'
)
{
if
(ch==
'-'
)
f=-1;
ch=
getchar
();
}
while
(ch<=
'9'
&&ch>=
'0'
)
{
x=(x<<3)+(x<<1)+ch-
'0'
;
ch=
getchar
();
}
return
f*x;
}
int
main()
{
int
c=read(),h=read(),j,i,b[100001],v[100001];
b[0]=1;
for
(i=1;i<=h;i++)
{
v[i]=read();
for
(j=c-v[i];j>=0;j--)
if
(b[j]) b[j+v[i]]=1;//核心,如果当前容量j可行,那么再放一个v[i]也一定可行
}
int
ans;
for
(i=0;i<=c;i++)
if
(b[i])ans=i;
cout<<ans;
}
bzo1606: [Usaco2008 Dec]Hay For Sale 购买干草的更多相关文章
- BZOJ1606: [Usaco2008 Dec]Hay For Sale 购买干草
1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 612 Solved: 46 ...
- BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
-------------------------------------------------------------------- #include<cstdio> #include ...
- bzoj1606[Usaco2008 Dec]Hay For Sale 购买干草(01背包)
1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1240 Solved: 9 ...
- [bzoj1606][Usaco2008 Dec]Hay For Sale 购买干草_动态规划_背包dp
Hay For Sale 购买干草 bzoj-1606 Usaco-2008 Dec 题目大意:约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单 ...
- 01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale
题面:P2925 [USACO08DEC]干草出售Hay For Sale 题解:无 代码: #include<cstdio> #include<cstring> #inclu ...
- bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- 1606: [Usaco2008 Dec]Hay For Sale 购买干草
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- [Usaco2008 Dec]Hay For Sale 购买干草[01背包水题]
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包 ...
- [BZOJ1606] [Usaco2008 Dec] Hay For Sale 购买干草 (dp)
Description 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每 ...
随机推荐
- Tensorflow生成唐诗和歌词(上)
整个工程使用的是Windows版pyCharm和tensorflow. 源码地址:https://github.com/Irvinglove/tensorflow_poems/tree/master ...
- Tensorflow:DCGAN生成手写数字
参考地址:https://blog.csdn.net/miracle_ma/article/details/78305991 使用DCGAN(deep convolutional GAN):深度卷积G ...
- 查看python脚本的运行pid,让python脚本后台运行
ps -ef | grep Productor.py | grep -v grep # 先测试好 python3 /usr/local/software/ELK/Productor.py # 没问题 ...
- Android.os.SystemClock
https://www.linuxidc.com/Linux/2011-11/48325p2.htm 文档中对System.currentTimeMillis()进行了相应的描述,就是说它不适合用在需 ...
- win10远程桌面出现身份验证错误。要求的函数不受支持
打开组策略,依次展开“计算机配置”->“管理模板”->“系统”->“凭据分配”,设置名称: “加密 Oracle 修正” 为已启用,并设置保护级别为“易受攻击”
- 一脸懵逼学习oracle(图形化界面操作---》PLSQL图形化界面)
1:经过几天的折腾,终于将oracle安装成功,创建用户,授权等等操作,接下来就安安心心学习oracle: 安装好PLSQL图形化界面和汉化以后(过程自己百度吧,百度more and more),登录 ...
- 微信公众平台开发教程Java版(六) 事件处理(菜单点击/关注/取消关注)
https://blog.csdn.net/tuposky/article/details/40589325
- 【Oracle】Linux7安装11g 86%报错:Error in invoking target 'agent nmhs' of makefile
http://blog.itpub.net/29475508/viewspace-2120836/
- [转] Lodash
与underscore 类似 , 是1个js库,内部封装了诸多对字符串.数组.对象等常见数据类型的处理函数. 模块组成 Lodash 提供的辅助函数主要分为以下几类,函数列表和用法实例请查看 Loda ...
- Summary of continuous function spaces
In general differential calculus, we have learned the definitions of function continuity, such as fu ...