https://www.luogu.org/problem/show?pid=2925

题目描述

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:

7 3
2
6
5
输出样例#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.

 #include <algorithm>
#include <cstdio> using namespace std; int n,m,w[];
int f[]; int main()
{
scanf("%d%d",&m,&n);
for(int i=;i<=n;i++)
scanf("%d",&w[i]);
for(int i=;i<=n;i++)
for(int j=m;j>=w[i];j--)
if(f[j-w[i]]+w[i]>f[j])
f[j]=f[j-w[i]]+w[i];
printf("%d",f[m]);
return ;
}

洛谷——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】

    题意翻译 题目描述 农民john面临一个很可怕的事实,因为防范失措他存储的所有稻草给澳大利亚蟑螂吃光了,他将面临没有稻草喂养奶牛的局面.在奶牛断粮之前,john拉着他的马车到农民Don的农场中买一些稻 ...

  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. 0619-dedeCMS数据表

    CMS的层级从前台分主要分为首页--栏目页--内容页,从后台分主要是四张表之间的关系: 1.模型表--dede_channeltype(顶级) 2.栏目表--dede_arctype 3.数据表:分为 ...

  2. php实现下载

    PHP实现下载文件的两种方法.分享下,有用到的朋友看看哦. 方法一: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <?php /** * 下载文件 * ...

  3. 我们的微信小程序开发

    基于微信小程序的系统开发准备工作 腾讯推出微信小程序也有一段时间了,在各种行业里面也都掀起一阵阵的热潮,很多APP应用被简化为小程序的功能迅速推出,同时也根据小程序的特性推出各种独具匠心的应用,相对传 ...

  4. [Apple开发者帐户帮助]九、参考(5)支持的功能(tvOS)

    tvOS应用程序可用的功能取决于您的程序成员身份. 能力 ADP 企业 Apple开发者 应用程序组 相关域名   背景模式 数据保护 游戏中心     游戏控制器 HomeKit iCloud:Cl ...

  5. [Apple开发者帐户帮助]八、管理档案(1)创建开发配置文件

    您可以在开发人员帐户中创建开发配置文件,以便在Xcode中手动签署应用程序时使用. 在开始之前,您需要一个App ID,一个或多个开发证书以及一个或多个已注册的设备.您可以使用Xcode为您管理的Ap ...

  6. vue-video-player视频播放插件

    安装依赖 npm install vue-video-player -S 引入配置 //main.js import 'video.js/dist/video-js.css' import 'vue- ...

  7. [转]linux之top命令

    转自:http://www.cnblogs.com/ggjucheng/archive/2012/01/08/2316399.html 简介 top命令是Linux下常用的性能分析工具,能够实时显示系 ...

  8. IIS: 响应消息的内容类型 text/html; charset=utf-8 与绑定(text/xml; charset=utf-8)的内容类型不匹配。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法

    以前好好的项目,突然出现了这个问题.一顿google后无果,有人说是程序池的原因,有人说是安全配置的原因,照着网上方法试了多次,还是没有解决.如下图: 突然发现了一片文章 (https://www.j ...

  9. 研磨JavaScript系列(三):函数的魔力

    JavaScript的代码中就只有function一种形式,function就是函数的类型.在其他的编程语言中可能还存在Procedure或者是method等代码概念,在JavaScript中只有fu ...

  10. Java&Xml教程(二)使用DOM方式解析XML文件

    DOM XML 解析方式是最容易理解的,它將XML文件作为Document对象读取到内存中,然后你可以轻松地遍历不同的元素和节点对象.遍历元素和节点不需要按照顺序进行. DOM解析方式适合尺寸较小的X ...