题意翻译

  1. 题目描述
  2. 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面。在奶牛断粮之前,john拉着他的马车到农民Don的农场中买一些稻草给奶牛过冬。已知john的马车可以装的下C(1 <= C <=50,000)立方的稻草。
  3. 农民DonH(1 <= H <= 5,000)捆体积不同的稻草可供购买,每一捆稻草有它自己的体积(1 <= V_i <= C)。面对这些稻草john认真的计算如何充分利用马车的空间购买尽量多的稻草给他的奶牛过冬。
  4. 现在给定马车的最大容积C和每一捆稻草的体积Vijohn如何在不超过马车最大容积的情况下买到最大体积的稻草?他不可以把一捆稻草分开来买。
  5. 输入输出格式
  6. 输入格式:
  7. 第一行两个整数,分别为CH
  8. 2..H+1行:每一行一个整数代表第i捆稻草的体积Vi
  9. 输出格式:
  10. 一个整数,为john能买到的稻草的体积。
  11. 输入输出样例
  12. 输入样例#1
  13. 7 3
  14. 2
  15. 6
  16. 5
  17. 输出样例#1
  18. 7

翻译提供者:黑客集团_鬼

题目描述

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.

输入输出样例

输入样例#1:
复制

  1. 7 3
  2. 2
  3. 6
  4. 5
输出样例#1: 复制

  1. 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.

  1. // luogu-judger-enable-o2
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<iomanip>
  7. #include<string>
  8. #include<algorithm>
  9. #include<cstdlib>
  10. using namespace std;
  11. int dp[],v[],c[],s[];
  12. int main()
  13. {
  14. int m,n;
  15. cin>>m>>n;
  16. for(int i=;i<=n;i++)
  17. {
  18. cin>>v[i];
  19. }
  20. for(int i=;i<=n;i++)
  21. {
  22. for(int j=m;j>=v[i];j--)
  23. {
  24. dp[j]=max(dp[j],dp[j-v[i]]+v[i]);
  25. }
  26. }
  27. cout<<dp[m];
  28. return ;
  29. }

这里其中一个点是优化过的

【洛谷P2925 [USACO08DEC]干草出售Hay For Sale】的更多相关文章

  1. 洛谷P2925 [USACO08DEC]干草出售Hay For Sale

    题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...

  2. 洛谷——P2925 [USACO08DEC]干草出售Hay For Sale

    https://www.luogu.org/problem/show?pid=2925 题目描述 Farmer John suffered a terrible loss when giant Aus ...

  3. 洛谷 P2925 [USACO08DEC]干草出售Hay For Sale

    嗯... 题目链接:https://www.luogu.org/problemnew/show/P2925 这是一道简单的01背包问题,但是按照正常的01背包来做会TLE一个点,所以要加一个特判(见代 ...

  4. 01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale

    题面:P2925 [USACO08DEC]干草出售Hay For Sale 题解:无 代码: #include<cstdio> #include<cstring> #inclu ...

  5. bzoj1606 / P2925 [USACO08DEC]干草出售Hay For Sale(01背包)

    P2925 [USACO08DEC]干草出售Hay For Sale 简化版01背包(连价值都免了) 直接逆推解决 #include<iostream> #include<cstdi ...

  6. 【洛谷】【动态规划/01背包】P2925 [USACO08DEC]干草出售Hay For Sale

    [题目描述:] 约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草. 顿因有H(1≤H≤5000)包干草,每一包都有它 ...

  7. P2925 [USACO08DEC]干草出售Hay For Sale

    传送门 把每体积的干草价值看成一,就变成求最大价值 直接上背包就行了 注意优化常数 #include<iostream> #include<cstdio> #include&l ...

  8. P2925 [USACO08DEC]干草出售Hay For Sale 题解

    \(\Huge{dp第一题}\) 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农 ...

  9. AC日记——[USACO08DEC]干草出售Hay For Sale 洛谷 P2925

    题目描述 Farmer John suffered a terrible loss when giant Australian cockroaches ate the entirety of his ...

随机推荐

  1. Netcat实用操作

    写久了web倦了,第n次开始尝试网络开发,于是熟悉一下常用工具. 尝试了一下netcat来测试服务器,或者充当客户端都异常好用.于是记录一下常用的一下命令 1. 充当服务器,或者客户端进行访问 通过n ...

  2. PHP金额工具类之将阿利伯数字转换为大写中文数字

    1.将阿拉伯数字转换为中文大写数字 <?php namespace core\components; class PriceHelper extends \yii\base\Component{ ...

  3. sqlserver数据库性能测试方法

    测试计划-添加jdbc jar 地址(数据驱动) jdbc configuration 地址 jdbc:sqlserver://127.0.0.1:1433;databasename=XSData j ...

  4. tomcat9 点击bin目录下的startup.bat一闪而过

    我装的是tomcat9免安装版,jdk版本是11,之后去tomcat bin目录下点击startup.bat闪退(好吧,只有想办法解决了) 博客中的解决办法五花八门,什么环境变量没配好....不过都不 ...

  5. codeforces559B

    Equivalent Strings CodeForces - 559B Today on a lecture about strings Gerald learned a new definitio ...

  6. System.Diagnostics.Process启动Civil 3D及AutoCAD

    QQ群友提出问题, 如何启动Civil 3D或者AutoCAD, Kean的博客里有相关的文章 http://through-the-interface.typepad.com/through_the ...

  7. 数据库SQL SELECT查询的工作原理

    一般开发员只会应用SQL的四条经典语句:select,insert,delete,update.但是我从来没有研究过它们的工作原理,这篇我想说一说select在数据库中的工作原理. B/S架构中最经典 ...

  8. HDU4651 Partition 【多项式求逆】

    题目分析: 这题的做法是一个叫做五边形数定理的东西,我不会. 我们不难发现第$n$项的答案其实是: $$\prod_{i=1}^{\infty}\frac{1}{1-x^i}$$ 我们要对底下的东西求 ...

  9. springMVC整理04--文件上传 & 拦截器 & 异常处理

    1.  文件上传 SpringMVC 的文件上传非常简便,首先导入文件上传依赖的 jar: <!-- 文件上传所依赖的 jar 包 --> <dependency> <g ...

  10. Java 元编程及其应用

    Java 元编程及其应用 首先,我们且不说元编程是什么,他能做什么.我们先来谈谈生产力. 同样是实现一个投票系统,一个是python程序员,基于django-framework,用了半小时就搭建了一个 ...