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 ...
随机推荐
- SQL Server获取月度列表
-- 获取月度列表 if exists(select 1 from sysobjects where name = 'proc_GetDateMonthList' and type = 'p') dr ...
- 说说Timing这回事(转载)
本文原始位置:FPGANotes Blog http://wiki.fpganotes.com/doku.php/ise:timing:my_summary Intro 问:一个FPGA设计项目需要用 ...
- POS管理系统之出入库单分页查询
JSP: <html> <head> <title>My JSP 'inOutKuPage.jsp' starting page</title> ...
- Java基础(二) ---- 继承(Inheritance)
- Linux:添加永久路由
没有以下文件时,可创建 vim /etc/sysconfig/network-scripts/route-eth0添加如下信息:192.168.142.100/32 via 192.168.142.1 ...
- solr5.5教程-Analyzer、Tokenizer、Filter
对于文本,solr在建立索引和搜索的时候需要对其做一定的处理(比如英文要去掉介词.转成小写.单词原形化等,中文要恰当地要分词).这些工作,一般由Analyzers.Tokenizers.和Filter ...
- 两种open()函数
C语言中文件操作函数中,open()有两种形式: 一种形式是有两个参数open2: 另一种形式是有三个参数open3: 共有的参数有两个,第一个是"被打开文件的路径",第二个是&q ...
- ARCGIS多种影像裁剪
在互联网上下载的遥感影像都进行过分幅处理,下载下来的影像多是规则的四方形,而在进行遥感影像研究时,多是针对特定区域来进行,比如研究北京市的遥感影像,不在北京市范围内的影像对于研究者就没有利用意义,如果 ...
- 装饰模式(Decorator pattern)
装饰模式(Decorator pattern): 又名包装模式(Wrapper pattern), 它以对客户端透明的方式扩展对象的功能,是继承关系的一个替代方案. 装饰模式以对客户透明的方式动态的给 ...
- VS CODE 下的 ESLint 安装以及使用
经过半年的前端磨练(就是不停地敲敲代码),自认水平提高的速度还是可以的. 现在回头看下写过的代码,发现以前写的代码真的是不忍惨睹. 比如 变量名乱起 风格多变 注释乱写或者没写 等等错误; 这不是一个 ...