--------------------------------------------------------------------

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
 
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 50000 + 5;
 
bool dp[ maxn ];
 
int main() {
freopen( "test.in" , "r" , stdin );
clr( dp , 0 );
int n , V;
cin >> V >> n;
while( n-- ) {
int t;
scanf( "%d" , &t );
for( int i = 0 ; i + t <= V ; i++ ) 
   if( dp[ i ] ) dp[ i + t ] = true;
   
dp[ t ] = true;
   
}
for( int i = V ; i >= 0 ; i-- ) if( dp[ i ] ) {
cout << i << "\n";
break;
}
return 0;
}

--------------------------------------------------------------------

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 743  Solved: 560
[Submit][Status][Discuss]

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

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

  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. bzoj 1606: [Usaco2008 Dec]Hay For Sale 购买干草

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

  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 购买干草 (dp)

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

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

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

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

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

随机推荐

  1. C++死锁解决心得

    一. 概述C++多线程开发中,容易出现死锁导致程序挂起的现象.关于死锁的信息,见百度百科http://baike.baidu.com/view/121723.htm. 解决步骤分为三步:1.检测死锁线 ...

  2. Google Maps API V2

    1. 在AndroidManifest.xml的application节点中,添加Google play service的版本号: <meta-data android:name="c ...

  3. 错误解决一_call time pass-by-reference removed

    我的操作: 定义function my_function(&$param) 调用 my_function(&$value)错误来了:Call-time pass-by-referenc ...

  4. python-大话装饰器

    装饰器 装饰器是个什么玩意呢?是个会了不难,装逼神器.但是如果不了解理解起来还是很抽象,让我们试试这个装逼神器吧! 1.什么是装饰器 装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典 ...

  5. iOS 处理方法中的可变參数

    ## iOS 处理方法中的可变參数 近期写了一个自己定义的对话框的demo,想模仿系统的UIAlertView的实现方式.对处理可变參数的时候,遇到了小问题,于是谷歌了一下.写下了处理问题的方法.记录 ...

  6. android可拖动排序GridView实现

    经常使用今日头条.网易新闻的同学们应该都会注意到用于管理多个频道的可拖动排序GridView,下面介绍一下可拖动的DragGridView的实现方法.代码放在GitHub上https://github ...

  7. Nodejs解析HTML网页模块 jsdom

    工作需要抓取某些网页,所以今天试用下了node下的jsdom模块.同样功能的还有jquery jsdom https://npmjs.org/package/jsdom API很简单. jsdom.e ...

  8. XX cannot be resolved to a type

    http://www.cnblogs.com/xuxm2007/archive/2011/10/20/2219104.html 我是project->clean...即可 原理:将工程中的.cl ...

  9. getMetaData()

    ResultSet resultset = null; ResultSetMetaData resultsetmetadata = null; resultsetmetadata = resultse ...

  10. Mac之vim普通命令使用

    Mac之vim普通命令使用 标签: vim命令 高级一些的编辑器,都会包含宏功能,vim当然不能缺少了,在vim中使用宏是非常方便的: :qx 开始记录宏,并将结果存入寄存器x q 退出记录模式 @x ...