POJ 3624 Charm Bracelet(01背包)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 34532 | Accepted: 15301 |
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
Source
//Accepted 212K 266MS C++ 395B
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std; int dp[];
int w[], d[];
int main(void)
{
int n,m;
while(scanf("%d%d", &n,&m)!=EOF){
for(int i=;i<n;i++)
scanf("%d%d",&w[i],&d[i]);
memset(dp, ,sizeof(dp));
for(int i=;i<n;i++)
for(int j=m;j>=w[i];j--)
dp[j] = max(dp[j], dp[j-w[i]] + d[i]);
printf("%d\n", dp[m]);
}
return ;
}
POJ 3624 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 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 ...
- poj 3624 Charm Bracelet 01背包问题
题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. 用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...
- 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 ...
- POJ 3624 Charm Bracelet(0-1背包模板)
http://poj.org/problem?id=3624 题意:给出物品的重量和价值,在重量一定的情况下价值尽可能的大. 思路:经典0-1背包.直接套用模板. #include<iostre ...
- POJ 3624 Charm Bracelet(01背包模板)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45191 Accepted: 19318 ...
- poj 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29295 Accepted: 13143 ...
随机推荐
- OpenGL学习笔记2——顶点数组
#pragma comment(lib,"glut32.lib") #pragma comment(lib,"glut.lib") #pragma commen ...
- Tiny_4412的NFS挂载
设备连接: 交叉网线 串口线 usb线 电源线 网络设置: 笔记本ubuntu:wifi处,设置IPv4设置“仅本地连接”,不要 ...
- STL之序列式容器list与forward_list
List (双向链表) 与 forwardlist (单向链表) 算是非常基础的数据结构了,这里只是简单介绍下其结构及应用. 以list为例: 其节点模板: template <class T& ...
- Android 6.0权限适配
targetSdkVersion 23以上,必须适配新的权限模式 安卓6.0及之后,权限分为三类 1.不涉及隐私的正常权限,如innernet2.危险权限 3.特殊权限 system_alert_w ...
- PS 使用首记 修改png图片的颜色
ps打开png图片文件 改颜色 1.魔棒工具,选择图片中的圆圈或方框,双击,选中,出现蚂蚁线. 2.右侧调好颜色 3.alt+delete颜色就改成功了.保存ok. 吸管工具,吸到颜色,存到色板.需要 ...
- Microsoft Azure 01 (Summarize)
What is Windows Azure? As a cloud platform from Microsoft that provides a wide range of different se ...
- thinkPHP--SQL查询
一.查询方式 ThinkPHP 提供了三种基本的查询方式:字符串条件查询.索引数组条件查询和对象条件查询. 在大多数情况下,推荐使用索引数组和对象方式作为查询条件,因为会更加安全 1.使用字符串作为条 ...
- iOS MVC, MVVM
在iOS app里,如果用传统的MVC模式,Model层就是数据,View层就是Storyboard,nib文件或者构建UI的代码,Controller层就是ViewController,负责协调Mo ...
- Nginx开启GZIP来压缩网页
HTTP协议上的GZIP编码是一种用来改进web应 用程序性能的技术.大流量的WEB站点常常使用GZIP压缩技术来让用户感受更快的速度.这一般是指WWW服务器中安装的一个功能,当有人来访问这个服务器中 ...
- 机器学习PR:k近邻法分类
k近邻法是一种基本分类与回归方法.本章只讨论k近邻分类,回归方法将在随后专题中进行. 它可以进行多类分类,分类时根据在样本集合中其k个最近邻点的类别,通过多数表决等方式进行预测,因此不具有显式的学习过 ...