题目意思:

给出N,M,N表示有N个物品,M表示背包的容量。接着给出每一个物品的体积和价值,求背包可以装在的最大价值。

http://poj.org/problem?

id=3624

题目分析:

o-1背包问题,转化方程。dp[j]:表示容量为j的时候,背包的最大价值

dp[j]=max(dp[j],dp[j-w[i]]+d[i]);

AC代码:

#include<iostream>
#include<cstring>
using namespace std;
int dp[20000],w[20000],d[20000];
int main()
{
int n,v;
while(cin>>n>>v){
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++){
cin>>w[i]>>d[i];
}
for(int i=0;i<n;i++){
for(int j=v;j>=w[i];j--){
dp[j]=max(dp[j],dp[j-w[i]]+d[i]);
}
}
cout<<dp[v]<<endl;
}
return 0;
}

poj3642 Charm Bracelet(0-1背包)的更多相关文章

  1. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

  2. POJ 3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Bessie has gone to the mall's jewelry store and spies a charm br ...

  3. POJ3624 Charm Bracelet 【01背包】

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22621   Accepted: 10157 ...

  4. poj 3524 Charm Bracelet(01背包)

    Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...

  5. POJ 3624 Charm Bracelet(01背包模板)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45191   Accepted: 19318 ...

  6. Charm Bracelet(01背包)

    Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...

  7. poj 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29295   Accepted: 13143 ...

  8. P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)

    题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...

  9. Charm Bracelet 一维01背包

    A - Charm Bracelet Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Su ...

  10. Poj3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Description Bessie has gone to the mall's jewelry store and spie ...

随机推荐

  1. 2014 I/O归来:Google连接一切

    6月,WWDC 2014与Google I/O  (大部分演讲视频都公开.Youtube须要FQ,很值得一看)相继召开.今年是我第三年參加Google I/O大会. 三年间.Google积累了非常多技 ...

  2. Web端server推送技术原理分析及dwr框架简单的使用

    1 背景 "server推送技术"(ServerPushing)是近期Web技术中最热门的一个流行术语.它是继"Ajax"之后又一个倍受追捧的Web技术.&qu ...

  3. 用jQuery实现鼠标在table上移动进行样式变化

    1.定义样式 <style type="text/css"> .striped        {            background-color:red;    ...

  4. <转载>Div+Css布局教程(-)CSS必备知识

    目录: 1.Div+Css布局教程(-)CSS必备知识 注:本教程要求对html和css有基础了解. 一.CSS布局属性 Width:设置对象的宽度(width:45px). Height:设置对象的 ...

  5. wxpython 32 位 ,python 64 位问题

    在安装Python Wxpython模块后,导入包的时候,会提示不支持64位的支持,需要安装Pythons 32 位,或者强制,使用Python 32 模式运行即可 在终端输入: defaults w ...

  6. QLockFile,QRunInfo

    http://doc.qt.io/qt-5/qlockfile.html http://www.dushibaiyu.com/2014/10/qruninfo-api-smple.html

  7. HDU 3480 DP+斜率优化

    题意:给你n个数字,然后叫你从这些数字中选出m堆,使得每一堆的总和最小,一堆的总和就是这一堆中最大值减去最小值的平方,最后要使得所有堆加起来的总和最小. 思路:对这些数字排序之后,很容易想到DP解法, ...

  8. osgi实战学习之路:5.生命周期及利用命令、装饰者模式实现基于socket交互Bundle命令demo

    生命周期中关键3个类: BundleActivator 入口点,类似main方法 BundleContext Bundle上下文对象,在执行期间,为应用程序提供操作osgi框架的方法 Bundle 代 ...

  9. 重载(overload),覆盖/重写(override),隐藏(hide)

    写正题之前,先给出几个关键字的中英文对照,重载(overload),覆盖/重写(override),隐藏(hide).在早期的C++书籍中,常常把重载(overload)和覆盖(override)搞错 ...

  10. Android学习4、Android该Adapter

    一.Adapter介绍 An Adapter object acts as a bridge between an AdapterView and the underlying data for th ...