poj 3524 Charm Bracelet(01背包)
Description
Bessie 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 Di
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
4 6
1 4
2 6
3 12
2 7
Sample Output
23 //依然是01背包基础题
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int value[],volume[],dp[]; int main()
{
int n,v;
while(cin>>n>>v)
{
for(int i=;i<=n;i++)
cin>>volume[i]>>value[i];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
for(int j=v;j>=volume[i];j--)
dp[j]=max(dp[j],dp[j-volume[i]]+value[i]);
cout<<dp[v]<<endl;
}
return ;
}
poj 3524 Charm Bracelet(01背包)的更多相关文章
- POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- POJ 3624 Charm Bracelet 0-1背包
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...
- POJ 3624 Charm Bracelet(01背包模板题)
题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ...
- 洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包
题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...
- 洛谷 P2871 [USACO07DEC]手链Charm Bracelet && 01背包模板
题目传送门 解题思路: 一维解01背包,突然发现博客里没有01背包的板子,补上 AC代码: #include<cstdio> #include<iostream> using ...
- poj 3624 Charm Bracelet 01背包问题
题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. 用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...
- poj3642 Charm Bracelet(0-1背包)
题目意思: 给出N,M,N表示有N个物品,M表示背包的容量.接着给出每一个物品的体积和价值,求背包可以装在的最大价值. http://poj.org/problem? id=3624 题目分析: o- ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
随机推荐
- mysql版本,根据经纬度定位排序sql
SELECT id,lng,lat,ROUND(6378.138*2*ASIN(SQRT(POW(SIN((lat1*PI()/180-lat*PI()/180)/2),2)+COS(lat1*PI( ...
- android studio 工程设置项
1.在<工程根目录>\build\generated文件夹中 存在 xxx.jar 这个文件是用来做单元测试用的,但该功能目前还处于实验阶段,不想用可以关了. 去掉勾后,clean一下工程 ...
- C#删除只读文件或文件夹(解决File.Delete无法删除文件)
引用: http://www.jb51.net/article/72181.htm C#删除只读文件的方法: if (File.GetAttributes(FFName).ToString().I ...
- [UWP小白日记-3]记账项目-1
学了一段时间的UWP,来个项目试试手. 本来是想边做边学MVVMLight的结果感觉MVVM对于萌新来说太高难,以后再把这个项目改造成MVVMLight框架的项目. 下面进入正题. 中间那快空白打算放 ...
- cursor属性
cursor光标类型 auto default none context-menu help pointer progress wait cell crosshair text vertical-te ...
- Struts2的通配符配置方式
Struts2的Action类很有意思,你可以使用3种方式来实现具体的Action类: 让你的Action类继承自ActionSupport类(项目中最常用这种方式,因为ActionSupport类中 ...
- action 耦合方式
//ActionContext 方式 package com.hanqi.action; import java.util.Map; import com.opensymphony.xwork2.Ac ...
- python基础(八)-迭代器与生成器
一.迭代器 li=[1,2,3] f=li.__iter__() print(f) print(f.__next__()) print(f.__next__()) print(f.__next__() ...
- 【实验室笔记】zedgraph控件属性总结
//图表的X轴刻度线是否显示 this.zedGraphControl1.GraphPane.XAxis.MajorGrid.IsVisible = true; //图表的X轴刻度线的颜色 this. ...
- 灾情巡视C语言代码
/*"水灾巡视问题"模拟退火算法.这是一个推销员问题,本题有53个点,所有可能性大约为exp(53),目前没有好方法求出精确解,既然求不出精确解,我们使用模拟退火法求出一个较优解, ...