BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草( dp )
2015-06-02 22:07
435 查看
![](http://images0.cnblogs.com/blog2015/723896/201506/022206175867646.png)
--------------------------------------------------------------------
#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 MBSubmit: 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
Silver相关文章推荐
- [Servlet3.0新特性]注解替代配置文件
- jQuery网站顶部定时折叠广告
- [Servlet3.0新特性]注解替代配置文件
- 如何在网上下载图片,表情使用迅雷下载更多文件
- [转]脏读,不可重复读,幻读的理解
- modelsim No objects found matching '/t/*' Xilinx IP核
- Solution of Codility
- New Beginning
- HDOJ 2018 母牛的故事
- 客运综合管理系统项目解析-安全检查(模块)-出站检查查询
- LeetCode 20: Valid Parentheses
- django web 中添加超链接
- Binary Tree Level Order Traversal II
- 最后期限2
- ORA-01940:无法删除当前已链接的用户
- 解决ORA-28000: the account is locked
- 终于解决“Git Windows客户端保存用户名与密码”的问题
- iOS开发系列--UITableView全面解析
- 文本处理
- LeetCode 19: Remove Nth Node From End of List