题目意思:

给出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. Struts 2最新0day破坏性漏洞(远程任意代码执行)等的重现方法

    Struts 2的远程任意代码执行和重定向漏洞,是这两天互联网上最重大的安全事件,据说国内互联网企业中,很多电商纷纷中招,应该已经有大规模的用户隐私泄露.这里我们简单总结下怎样在自己机子上重现这些漏洞 ...

  2. S3C3440看门狗驱动程序

    S3C3440看门狗驱动程序 http://www.cnblogs.com/lfsblack/archive/2012/09/13/2684079.html 看门狗是当CPU进入错误状态后,无法恢复的 ...

  3. Windows Azure入门教学系列 (五):使用Queue Storage

    本文是Windows Azure入门教学的第五篇文章. 本文将会介绍如何使用Queue Storage.Queue Storage提供给我们一个云端的队列.我们可以用Queue Storage来进行进 ...

  4. js点击button按钮跳转到另一个新页面

    点击按钮怎么跳转到另外一个页面呢?我们在网站制作中可能是需要的,因为有时我们需要做这样的效果,尤其是将按钮做成一个图片,而点击图片要跳转到新的页面时,怎么做到呢? 这样的效果可以:onclick=&q ...

  5. 【Demo 0006】Android 组件(Activity)

    本章学习要点:        1.  了解Activity基本概念;        2.  掌握Activity生命周期:        3.  掌握 Activity之间跳转:  

  6. 全方位深度剖析--性能测试之LoardRunner 介绍

    一.介绍 LoardRunner是一种预测系统行为和性能负载的测试工具.通过模拟上千万用户实施并发负载及实时性能监控的方式来确认和查找系统的瓶颈,LoardRunner能够对整个企业架构进行测试.通过 ...

  7. 在程序异常中记录堆栈信息(使用ExWatcher)

    在我们编写程序的时候可通过IDE自带的调试环境捕捉到异常(Except)错误,并能查看到相关的信息以便我们修正程序中的问题.但当软件被发布出去后,因为所部署运行的环境与我们的调试环境有很大区别,即使在 ...

  8. 14.2.1 MySQL and the ACID Model

    14.2 InnoDB Concepts and Architecture InnoDB 概念和结构体系: 14.2.1 MySQL and the ACID Model 14.2.2 InnoDB ...

  9. Swift - 让StoryBoard设计视图,程序运行时都使用横屏形式

    1,运行时横屏 将项目属性“General”->“DeviceOritentation”的Portrait复选框去掉 2,storyboard设计视图横屏 在storyboard中,单击中间界面 ...

  10. uploadfiy使用

    动态加参数:$("#file_upload").uploadify("settings", "formData", { knowledgeI ...