题目描述

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 main()
{
    scanf("%d%d",&v,&n);
    ;i<=n;i++)
        scanf("%d",&w[i]);
    ;i<=n;i++)
        for(int m=v;m>=w[i];m--)
            if(f[m-w[i]]+w[i]>f[m])
                f[m]=f[m-w[i]]+w[i];
    printf("%d",f[v]);
    ;
}

洛谷 ——2925干草出售Hay For Sale的更多相关文章

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

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

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

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

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

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

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

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

  5. 【洛谷P2925 [USACO08DEC]干草出售Hay For Sale】

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

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

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

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

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

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

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

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

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

随机推荐

  1. 【Max Points on a Line 】cpp

    题目: Given n points on a 2D plane, find the maximum number of points that lie on the same straight li ...

  2. 命名空间“System.Web.Http”中不存在类型或命名空间名称“Description”(是否缺少程序集引用?)

    solution: Set "Copy Local : True" in properties for References\System.Web.Http   在http://s ...

  3. 每天一个Linux命令(8):chmod命令

    chmod命令用来变更文件或目录的权限. 权限范围的表示法如下: u   User,即文件或目录的拥有者:g  Group,即文件或目录的所属群组:o   Other,除了文件或目录拥有者或所属群组之 ...

  4. 关于MySQL查询优化 の 30条忠告

    撸自:http://www.jincon.com/archives/120/ 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避 ...

  5. 孤荷凌寒自学python第四十八天通用同一数据库中复制数据表函数最终完成

    孤荷凌寒自学python第四十八天通用同一数据库中复制数据表函数最终完成 (完整学习过程屏幕记录视频地址在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 今天经过反复折腾,最终基本上算 ...

  6. leetcode_day03

    https://leetcode-cn.com/problems/container-with-most-water/ 题目:盛水最多的容器 给定 n 个非负整数 a1,a2,...,an,每个数代表 ...

  7. Android 之高仿微信主界面

    源码下载:  http://files.cnblogs.com/aibuli/WeChatSample.zip 主界面主要使用ActionBar来完成.  要实现这个效果,第一步当然是编辑menu目录 ...

  8. PAT 1075 链表元素分类

    https://pintia.cn/problem-sets/994805260223102976/problems/994805262953594880 给定一个单链表,请编写程序将链表元素进行分类 ...

  9. 移动平台自动化测试:appium(二)

    环境搭建.本环境基于win7_x64搭建 安装环境需要用到的工具清单: android sdk:https://developer.android.com/studio/index.html Appi ...

  10. UVA1316 Supermarket

    题目描述 有一个商店有许多批货,每一批货又有N(0<=N<= 10^4104 )个商品,同时每一样商品都有收益 P_iPi​ ,和过期时间 D_iDi​ (1<= Pi,DiPi,D ...