NYOJ 289 (0-1背包)
2014-03-23 20:49
225 查看
#include <iostream> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 1010; int MAX(int a, int b) { return a > b ? a : b; } int dp[MAXN]; int V; void Zero_One_Pack(int cost, int Price) { for(int v = V; v >= cost; --v) dp[v] = MAX(dp[v], dp[v - cost] + Price); } int main() { int n; int cost, price; while(~scanf("%d %d", &n, &V) && n && V) { memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; ++i) { scanf("%d %d", &cost, &price); Zero_One_Pack(cost, price); } cout<<dp[V]<<endl; } return 0; }
相关文章推荐
- C语言数据类型与openGL数据类型
- ZigBee介绍
- FFT快速傅立叶变换
- Java你现在正在使用哪个版本
- OpenGL+QT实现矢量和影像的叠加绘制
- 解决eclipse的source not found change at.
- Unity3D研究院之控制模型移动旋转与碰撞(七)
- Ruby gem包的管理
- ptrace
- Oracle
- NYOJ 311 完全背包
- ptrace
- vs2010 +Ogre配置
- Android MediaScanner:(一)(二)(三)(四)
- 设计模式之六:工厂模式汇总
- PL/SQL编程3
- nyoj_274正三角形的外接圆面积
- poj2288之求有多少条哈密顿路
- zoj 1184
- cocos2dx3.0的项目属性继承 (vs2012)