Description

    约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草.  顿因有H(1≤H≤5000)包干草,每一包都有它的体积Vi(l≤Vi≤C).约翰只能整包购买,
他最多可以运回多少体积的干草呢?

Input

    第1行输入C和H,之后H行一行输入一个Vi.

Output

 
    最多的可买干草体积.

Sample Input

7 3 //总体积为7,用3个物品来背包
2
6
5

The wagon holds 7 volumetric units; three bales are offered for sale with
volumes of 2, 6, and 5 units, respectively.

Sample Output

7 //最大可以背出来的体积

HINT

Buying the two smaller bales fills the wagon.

Source

http://www.lydsy.com/JudgeOnline/problem.php?id=1606

01背包

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

bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草的更多相关文章

  1. BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )

    -------------------------------------------------------------------- #include<cstdio> #include ...

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

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

  3. BZOJ——1606: [Usaco2008 Dec]Hay For Sale 购买干草

    http://www.lydsy.com/JudgeOnline/problem.php?id=1606 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1 ...

  4. BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草(动态规划)

    裸的背包= =,没什么好说的= = CODE: #include<cstdio>#include<iostream>#include<algorithm>#incl ...

  5. bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草【01背包】

    在洛谷上被卡常了一个点! 就是裸的01背包咯 为啥我在刷水题啊 #include<iostream> #include<cstdio> #include<algorith ...

  6. 1606: [Usaco2008 Dec]Hay For Sale 购买干草

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

  7. BZOJ1606: [Usaco2008 Dec]Hay For Sale 购买干草

    1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 612  Solved: 46 ...

  8. bzo1606: [Usaco2008 Dec]Hay For Sale 购买干草

    1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1338  Solved: 9 ...

  9. bzoj1606[Usaco2008 Dec]Hay For Sale 购买干草(01背包)

    1606: [Usaco2008 Dec]Hay For Sale 购买干草 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1240  Solved: 9 ...

随机推荐

  1. POI导入导出

    一.使用POI导出Execl表格 需要的jar包 package cn.yxj.poi; import java.io.FileOutputStream; import java.util.Date; ...

  2. Unable to extract 64-bitimage. Run Process Explorer from a writeable directory

    Unable to extract 64-bitimage. Run Process Explorer from a writeable directory When we run Process E ...

  3. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q142-Q143)

    Question 142You have a Feature that contains an image named ImageV1.png.You plan to create a new ver ...

  4. textview设置drawable

    textview可以在上下左右四个方向添加图片,同时也可以动态改变这些图片:   下面有我写的一个例子: 在xml文件中:  <TextView                 android: ...

  5. shareSDK实现分享操作时只显示英文字体

    今天用shareSDK实现分享操作时,突然发现分享视图只显示英文字体,而之前是显示中文的,以下是自己找到的解决方法: ,首先,找到shareSDk里的“ShareSDKUI_Localizable.s ...

  6. iOS Swift-控制流(The Swift Programming Language)

    iOS Swift-控制流(The Swift Programming Language) for-in 在Swift中for循环我们可以省略传统oc笨拙的条件和循环变量的括号,但是语句体的大括号使我 ...

  7. OC 协议

    OC 协议 概念:定义了一个接口,其他类负责来实现这些接口.如果你的类实现了一个协议的方法时,则说该类遵循此协议. 非正式协议:非正式协议虽名为协议,但实际上是挂于NSObject上的未实现分类(Un ...

  8. jquery 获取多个select name 的值

    html {foreach from=$month_arr item=dateArr key=i}<tr> <td>{$dateArr.m}</td> <td ...

  9. Play Framework 完整实现一个APP(三)

    1.添加Post类 package models; import java.util.*; import javax.persistence.*; import play.db.jpa.*; @Ent ...

  10. ORA-04091: table xxxx is mutating, trigger/function may not see it

    今天同事让我看一个触发器为什么老是报错,当执行DML语句触发触发器后,会报ORA-04091错误:ORA-04091: table xxxx is mutating, trigger/function ...