AC日记——[USACO08DEC]干草出售Hay For Sale 洛谷 P2925
题目描述
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.
思路:
最后一个点诶。。。
死活过不去;;
来,上代码:
#include <cstdio>
#include <iostream> using namespace std; int if_z,n,m,dp[]; char Cget; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
} int main()
{
in(m),in(n);int pos;
while(n--)
{
in(pos);
//for(int i=m;i>=pos;i--) dp[i]=max(dp[i],dp[i-pos]+pos);
for(int i=m;i>=pos;i--)
{
if(dp[i-pos]+pos>dp[i]) dp[i]=dp[i-pos]+pos;
}
}
cout<<dp[m];
return ;
}
正解!
#include <iostream> using namespace std; int n; int main()
{
cin>>n;
cout<<n;
return ;
}
AC日记——[USACO08DEC]干草出售Hay For Sale 洛谷 P2925的更多相关文章
- 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 ...
- 洛谷P2925 [USACO08DEC]干草出售Hay For Sale
题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...
- 【洛谷P2925 [USACO08DEC]干草出售Hay For Sale】
题意翻译 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农民Don的农场中买一些稻 ...
- 【洛谷】【动态规划/01背包】P2925 [USACO08DEC]干草出售Hay For Sale
[题目描述:] 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每一包都有它 ...
- 洛谷——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 题解
\(\Huge{dp第一题}\) 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农 ...
- P2925 [USACO08DEC]干草出售Hay For Sale
传送门 把每体积的干草价值看成一,就变成求最大价值 直接上背包就行了 注意优化常数 #include<iostream> #include<cstdio> #include&l ...
- 洛谷 P2925 [USACO08DEC]干草出售Hay For Sale
嗯... 题目链接:https://www.luogu.org/problemnew/show/P2925 这是一道简单的01背包问题,但是按照正常的01背包来做会TLE一个点,所以要加一个特判(见代 ...
随机推荐
- python_112_网络编程 Socket编程
实例1:客户端发小写英文,服务器端返回给客户端大写英文(仅支持一次接受发送) 服务器端: #服务器端(先于客户端运行) import socket server=socket.socket() ser ...
- remote: Incorrect username or password ( access token ) fatal: Authentication failed for
gitee推送到远程仓库时提示错误remote: Incorrect username or password ( access token )fatal: Authentication failed ...
- javaEE(15)_Servlet过滤器
一.Filter简介 1.Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, ...
- python面向对象编程(OOP)
python作为一种解释性语言,其主要的编程方式就是面向对象,而且python的框架django也是主要面向对象的编程. 类(class)和对象(object) 类(class)是用来描述具有相同属性 ...
- python3.x中的33个保留字
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type " ...
- mysqldump指令说明
3种形式mysqldump [OPTIONS] database [tables]mysqldump [OPTIONS] -B | --databases [OPTIONS] DB1 [DB2 DB3 ...
- 命令行发送UDP
https://www.cnblogs.com/Dennis-mi/articles/6866762.html: 如果往本地UDP端口發送數據,那麼可以使用以下命令:echo “hello” > ...
- centos7.2安装redis与配置(史上最全)
学习了php已经快三年了,一直是在盲目的忙,也没整理下笔记,今天整理一下 分享下安装redis的方法 #首先去redis官网去下载 http://www.redis.cn/download.htm ...
- 自定义View画一条线
#import "PublishContextView.h" @implementation PublishContextView -(void)drawRect:(CGRect) ...
- (原)剑指offer之位运算
题目描述 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 思路: count为1的位数,初始为零 每次右移一为,与1做与运算,结果不为零说明最后一位为1 c++代码如下 in ...