题目描述

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. 每天一个Linux命令(10):mv命令

    mv命令用来对文件或目录重新命名,或者将文件从一个目录移到另一个目录中.source表示源文件或目录,target表示目标文件或目录.如果将一个文件移到一个已经存在的目标文件中,则目标文件的内容将被覆 ...

  2. [shell]查找网段内可用IP地址

    #网段可用IP地址 #!/bin/sh ip= " ]; do .$ip -c |grep -q "ttl=" && echo "10.86.8 ...

  3. 设置EntityFramework中decimal类型数据精度问题(EF默认将只会保留到2为精度)

    原文:设置EntityFramework中decimal类型数据精度 EF中默认的decimal数据精度为两位数,当我们数据库设置的精度大于2时,EF将只会保留到2为精度. e.g. .19990将会 ...

  4. Rational Rose 使用技巧

    1.浏览区 2.菜单项 其中Format选项中: 决定各项是否显示,也可以通过右击-option选择 3.常用快捷键: F1:任何时候都可以按F1获得相关帮助,把鼠标放在某条菜单上按F1可以获得这条菜 ...

  5. CentOS程序 开机启动设置与chkconfig命令学习

    CentOS设置程序开机启动的方法: 1.启动命令添加到/etc/rc.d/rc.local 文件中, 如: vim /etc/rc.d/rc.local #!/bin/sh # # This scr ...

  6. nagios客户端安装

    在被监控服务器(Linux/unix)上安装Nagios-plugins和nrpe 1.添加用户   1 2 ; html-script: false ]/usr/sbin/useradd -m na ...

  7. JS计算器(自制)

    <!doctype html><html><header><meta charset="utf-8"><script src= ...

  8. [bzoj] 3263 陌上花开 洛谷 P3810 三维偏序|| CDQ分治 && CDQ分治讲解

    原题 定义一个点比另一个点大为当且仅当这个点的三个值分别大于等于另一个点的三个值.每比一个点大就为加一等级,求每个等级的点的数量. 显然的三维偏序问题,CDQ的板子题. CDQ分治: CDQ分治是一种 ...

  9. POJ 3977 Subset | 折半搜索

    题目: 给出一个整数集合,求出非空子集中元素和绝对值最小是多少(元素个数尽量少) 题解: 分成两半 爆搜每一半,用map维护前一半的值 每搜出后一半的一个值就去map里找和他和绝对值最小的更新答案 # ...

  10. NOIP2017赛前考试注意事项总结

     考前: 考试前把读入优化和库以及对拍文件打好做好准备工作,另外注意放松心态,太紧张了肯定考不好··将自己的注意力集中起来  考场策略: 考试的基本策略是对每于道题先想个20分钟,如果想不出个靠谱的方 ...