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. Gym - 101208C 2013 ACM-ICPC World Finals C.Surely You Congest 最大流+最短路

    题面 题意:给你n(2w5)个点,m条边(7w5)有k(1e3)辆车停在某些点上的,然后他们都想尽快去1号点,同时出发,同一个点不允许同时经过, 如果多辆车同时到达一个点,他们就会堵塞,这时候只能选择 ...

  2. Java8080端口被占用解决办法

    netstat -ano | findstr 8080 taskkill -pid 3196-f

  3. NetCore Netty 框架 BT.Netty.RPC 系列随讲 二 WHO AM I 之 NETTY/NETTY 与 网络通讯 IO 模型之关系?

    一:NETTY 是什么? Netty 是什么?  这个问题其实百度上一搜一堆. 这是官方话的描述:Netty 是一个基于NIO的客户.服务器端编程框架,使用Netty 可以确保你快速和简单的开发出一个 ...

  4. [ USACO 2018 OPEN ] Out of Sorts (Gold)

    \(\\\) \(Description\) 运行以下代码对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: cnt = 0 sorted = false while (not sorted ...

  5. [转]Wote用python语言写的imgHash.py

    #!/usr/bin/python import glob import os import sys from PIL import Image EXTS = 'jpg', 'jpeg', 'JPG' ...

  6. @ResponseBody 返回中文乱码

    第一种解决方法:在@RequestMapping注解添加produces属性 @RequestMapping(value = "testPersonalValidtor.do",p ...

  7. CDR服装设计-用CorelDRAW排钻如何把圈摆均匀

    服装设计一直都是一个很火热的行业,也是一个比较高端的行业,随着时代的步伐,以前的人都是用手绘的方式来设计服装,现在不一样了,电脑可以说普及到了每一个家庭,让软件以更快的速度,更准确的数据来设计服装中的 ...

  8. CPU重要性能参数

    内容来自http://www.360doc.com/content/18/1124/15/60810319_796935567.shtml CPU有几个重要的参数:主频.核心.线程.缓存.架构.那么他 ...

  9. 删数据ORA-02292主键约束问题

    通常在删除某个表A的时候,会出现这个错误.原因是另一个表B的某个字段引用了A表的某个字段作为约束(这个的另一个说法是外键). 假如引用的字段叫field,当B.field = A.field , 而你 ...

  10. Python random模块&string模块 day3

    一.random模块的使用: Python中的random模块用于生成随机数.下面介绍一下random模块中最常用的几个函数. 1.常用函数: (1)random.random() 用于生成一个0到1 ...