01背包(就地滚动)
来源:互联网 发布:网络借贷法律 编辑:程序博客网 时间:2024/05/22 08:26
<span style="color:#3333ff;">/*__________________________________________________________________________________________________* copyright: Grant Yuan ** algorithm: 01背包(就地滚动) ** time : 2014.7.18 ** declare : 题目中说N最大是3400多,但是一开始开了5000内存还是运行时错误,后来直接改了50000 * * **_________________________________________________________________________________________________*</span>
<span style="color:#3333ff;">I - 01背包(就地滚动)Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi ≤ 400), a 'desirability' factor Di (1 ≤ Di ≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M (1 ≤ M ≤ 12,880).Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.Input* Line 1: Two space-separated integers: N and M* Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and DiOutput* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraintsSample Input4 61 42 63 122 7Sample Output23*/#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>using namespace std;int w[50001];int p[50001];int sum;int n;int dp[50001];int main(){cin>>n>>sum;for(int i=0;i<n;i++)cin>>w[i]>>p[i];memset(dp,0,sizeof(dp));for(int i=0;i<n;i++) for(int j=sum;j>=w[i];j--) {dp[j]=max(dp[j],dp[j-w[i]]+p[i]); }cout<<dp[sum]<<endl;return 0;}</span>
0 0
- 01背包(就地滚动)
- 就地滚动处理0-1背包
- 01背包(滚动数组)
- POJ 2184(01背包+滚动数组)
- 采药-01背包+滚动数组
- POJ - 3624 Charm Bracelet (滚动数组/01背包)
- POJ 3624- Charm Bracelet(01背包 滚动数组)
- HDU 2602 Bone Collector(01二维背包&一维背包&滚动数组优化二维背包的原理 )
- hdu 1203 01背包 滚动数组
- 知识点:01背包(多种姿势:二维实现+一维实现+滚动数组实现+背包装满+输出最优方案)
- HDU 2602 Bone Collector(附01背包滚动数组的理解)
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包(01背包、完全背包、多重背包)问题总结
- 背包模板(01背包,完全背包,多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包 + 完全背包 + 多重背包)
- 背包问题(01背包,完全背包,多重背包)
- j2EE通用jar包的作用
- Web前端注意事项
- Order by/子查询 吸收索引 快速测试 ....
- 介绍两个Python web框架:Django & Tornado
- Android 根据角度旋转图片
- 01背包(就地滚动)
- 常见HTTP状态(304,200等)
- ipod touch cases vPW5 ZSdD 0Eai
- fifa ultimate team coins Wabl n0GQ 96FD
- android 支付宝快捷支付
- C++ Tree
- 如何成为一个卓越的程序员
- cheap jordan for sale SMRC 3JUV GYDh
- 【转】VC++,掀起你的盖头来 ——谈VC++对象模型