洛谷P2925 [USACO08DEC]干草出售Hay For Sale
题目描述
Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his hay inventory, leaving him with nothing to feed the cows. He hitched up his wagon with capacity C (1 <= C <= 50,000) cubic units and sauntered over to Farmer Don's to get some hay before the cows miss a meal.
Farmer Don had a wide variety of H (1 <= H <= 5,000) hay bales for sale, each with its own volume (1 <= V_i <= C). Bales of hay, you know, are somewhat flexible and can be jammed into the oddest of spaces in a wagon.
FJ carefully evaluates the volumes so that he can figure out the largest amount of hay he can purchase for his cows.
Given the volume constraint and a list of bales to buy, what is the greatest volume of hay FJ can purchase? He can't purchase partial bales, of course. Each input line (after the first) lists a single bale FJ can buy.
约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每一包都有它的体积Vi(l≤Vi≤C).约翰只能整包购买,
他最多可以运回多少体积的干草呢?
输入输出格式
输入格式:
Line 1: Two space-separated integers: C and H
- Lines 2..H+1: Each line describes the volume of a single bale: V_i
输出格式:
- Line 1: A single integer which is the greatest volume of hay FJ can purchase given the list of bales for sale and constraints.
输入输出样例
7 3
2
6
5
7
说明
The wagon holds 7 volumetric units; three bales are offered for sale with volumes of 2, 6, and 5 units, respectively.
Buying the two smaller bales fills the wagon.
01背包。常数看着挺大但是不会T
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int f[];
int n,c,v[];
int main(){
c=read();n=read();
int i,j;
for(i=;i<=n;i++)v[i]=read();
f[]=;
for(i=;i<=n;i++){
for(j=c;j>=v[i];j--){
f[j]|=f[j-v[i]];
}
}
for(j=c;j>=;j--){
if(f[j]){
printf("%d\n",j);
break;
}
}
return ;
}
洛谷P2925 [USACO08DEC]干草出售Hay For Sale的更多相关文章
- 【洛谷P2925 [USACO08DEC]干草出售Hay For Sale】
题意翻译 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农民Don的农场中买一些稻 ...
- 洛谷——P2925 [USACO08DEC]干草出售Hay For Sale
https://www.luogu.org/problem/show?pid=2925 题目描述 Farmer John suffered a terrible loss when giant Aus ...
- 洛谷 P2925 [USACO08DEC]干草出售Hay For Sale
嗯... 题目链接:https://www.luogu.org/problemnew/show/P2925 这是一道简单的01背包问题,但是按照正常的01背包来做会TLE一个点,所以要加一个特判(见代 ...
- 01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale
题面:P2925 [USACO08DEC]干草出售Hay For Sale 题解:无 代码: #include<cstdio> #include<cstring> #inclu ...
- bzoj1606 / P2925 [USACO08DEC]干草出售Hay For Sale(01背包)
P2925 [USACO08DEC]干草出售Hay For Sale 简化版01背包(连价值都免了) 直接逆推解决 #include<iostream> #include<cstdi ...
- 【洛谷】【动态规划/01背包】P2925 [USACO08DEC]干草出售Hay For Sale
[题目描述:] 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每一包都有它 ...
- P2925 [USACO08DEC]干草出售Hay For Sale
传送门 把每体积的干草价值看成一,就变成求最大价值 直接上背包就行了 注意优化常数 #include<iostream> #include<cstdio> #include&l ...
- P2925 [USACO08DEC]干草出售Hay For Sale 题解
\(\Huge{dp第一题}\) 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农 ...
- AC日记——[USACO08DEC]干草出售Hay For Sale 洛谷 P2925
题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...
随机推荐
- 转: 使用virtualenv搭建独立的Python环境
转自: http://qicheng0211.blog.51cto.com/3958621/1561685 谢谢作者的辛苦付出 virtualenv可以搭建虚拟且独立的python环境,可以使每个项 ...
- 啊D工具语句 适合Access和Mssql注入
啊D注入工具中使用的SQL注入语句 爆user )) )= | ***** ?Id)) : ?Id : Id 检查SA权限:)))) 爆当前库: )) -- 检查是否为mssql数据库:and exi ...
- 承香墨影 Android--Matrix图片变换处理
承香墨影 Android--Matrix图片变换处理 前言 本篇博客主要讲解一下如何处理对一个Bitmap对象进行处理,包括:缩放.旋转.位移.倾斜等.在最后将以一个简单的Demo来演示图片特效的变换 ...
- 当文本溢出包含的元素时加省略号之text-overflow
text-overflow是css3的属性,用来处理文本溢出,默认裁剪处理,text-overflow属性只能用于block和inline-block元素,内联的和box,flex-flow:colu ...
- 如何用chrome插件使上网生活更美好-持续更新
所有插件都可以到Chrome Web Store搜索下载 1.Read Later Fast v-1.6.8 ***刷网页的时候,有很多值得我们阅览但当时木有时间看怎么办? --加可书签啊! ***可 ...
- Gitub
1.下载地址(注册:jackchn,jackchn@foxmail.com) http://windows.github.com/ 2.使用 github for Windows使用介绍 搭建一个免费 ...
- 开源(免费)三维 GIS(地形,游戏)
先写想法: 想做个简单的地形漫游,于是考虑在ww直接开发,或找个控件形式的开发组件. 最大的期望有: 1. 支持google的sketchup,快速智能三维建模 2. 设计模式做好点,最好先做成组件形 ...
- php基础19:文件
<?php //1.打开文件的更好的方法是通过 fopen() 函数.此函数为您提供比 readfile() 函数更多的选项. //fopen() 的第一个参数包含被打开的文件名,第二个参数规定 ...
- Java系列:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
Javaweb工程类中没有添加Tomcat运行时相关类导致. 下面是具体的解决方法: 1.右击web工程->属性或Build Path->Java Build Path->Libra ...
- PLC梯形图编程练习
在PLC培训软件中完成如下两个练习,并把对应的梯形图程序发表在博客上. 交通灯控制 在如下图的场景中,打开SW1开关后,交通灯控制器开始工作,关闭SW1则控制器停止工作. SW2为控制模式选择开关: ...