poj3642 Charm Bracelet(0-1背包)
题目意思:
给出N,M,N表示有N个物品,M表示背包的容量。接着给出每一个物品的体积和价值,求背包可以装在的最大价值。
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背包)的更多相关文章
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
- 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 ...
- POJ3624 Charm Bracelet 【01背包】
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22621 Accepted: 10157 ...
- poj 3524 Charm Bracelet(01背包)
Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...
- POJ 3624 Charm Bracelet(01背包模板)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45191 Accepted: 19318 ...
- Charm Bracelet(01背包)
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...
- poj 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29295 Accepted: 13143 ...
- P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)
题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...
- Charm Bracelet 一维01背包
A - Charm Bracelet Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Su ...
- Poj3624 Charm Bracelet (01背包)
题目链接:http://poj.org/problem?id=3624 Description Bessie has gone to the mall's jewelry store and spie ...
随机推荐
- 谁知道哪有比较好的Beijing Milonga?想去参加这样的阿根廷探戈舞会~
谁知道哪有比较好的Beijing Milonga?想去参加这样的阿根廷探戈舞会~_百度知道 谁知道哪有比较好的Beijing Milonga?想去参加这样的阿根廷探戈舞会~ 2009-1 ...
- RFS的web自动化验收测试——第14讲 万能的evaluate
引言:什么是RFS——RobotFramework+Selenium2library,本系列主要介绍web自动化验收测试方面. ( @齐涛-道长 新浪微博) 这一讲我们重点来介绍一下一个常用的关键字e ...
- Managing your Actor Systems
今天偶然得机会,找到一篇不错得文章,现在分享给大家. 原文:http://www.kotancode.com/2013/02/15/managing-your-actor-systems/ If yo ...
- Taxonomy of class loader problems encountered when using Jakarta Commons Logging(转)
Acknowledgments I would like to thank Jacob Kjome for reviewing early drafts of this document. His c ...
- MyEclipse-6.5注冊码生成器源代码
打开MyEclipse新建一个Javaproject,然后新建类,粘贴例如以下代码,就可以生成MyEclipse的注冊码 import java.io.BufferedReader; import j ...
- struts2 一个简洁的struts.xml
struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUB ...
- 查看内存数据的函数(ByteToHex和ByteToBin,最终都变成String)
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Thymeleaf模板的使用
使用模板的要点: 页面主体结构固定,具体参数可变,尽可能让参数动态化,才能提高模板的复用性 ================================================== ...
- c++ anonymous union,struct -- 匿名联合体和机构体
c++ anonymous union,struct -- 匿名联合体和机构体 结构体和联合体各自的基本用法不赘述,仅说一下他们匿名时访问的情况.如果是token不同,可以直接跨层访问.例子 #inc ...
- linux下安装node.js
1.下载 wget http://nodejs.org/dist/v0.10.32/node-v0.10.32-linux-x64.tar.gz 2.解压 tar -xvf node-v0.10.32 ...