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 ...
随机推荐
- eclispe 无法启动调试 cannot connect to VM
eclispe中,点击调试运行java项目,出现 cannot connect to VM 正常的运行项目,没问题: 以为是jdk的安装路径等的问题,还有杀毒软件等等,都没有正常: 后来找到是wins ...
- C程序与Lua脚本相互调用
Lua脚本是一种可用于C程序开发/测试的工具,本篇介绍一下C程序与Lua脚本如何进行相互调用,更加详细的操作参见<Programing in Lua>.本文分为3个部分:1.Windows ...
- ajaxpro返回值类型总结-DataTable(转)
ajaxpro使用总结系列其他内容 ajaxpro ajaxmethod 重载调用问题 ajaxpro方法ajaxmethod调用示例 ajaxpro返回值类型总结-string,int ajaxpr ...
- PD脚本导出到数据库后没有注释问题
昨天PD里建了几张表,建表的时候我在NAME栏位写了中文说明,但是脚本在数据库里生成表以后,发现中文说明没有了,需要自己在“注释”栏位添加才行,如下图: 我想要达到的效果如下图: 解决方法: 1. ...
- Java:国际化
Java的国际化: 资源文件的命名可以有如下三种形式:baseName _ language _country.properties baseName _language.properties bas ...
- 牛客网程序员面试金典:1.1确定字符互异(java实现)
问题描述: 请实现一个算法,确定一个字符串的所有字符是否全都不同.这里我们要求不允许使用额外的存储结构. 给定一个string iniString,请返回一个bool值,True代表所有字符全都不同, ...
- 从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败问题解决方法
从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft ...
- .NET牛人应该知道些什么
任何一个使用.NET的人 1.描述线程与进程的区别? 线程(Thread)与进程(Process)二者都定义了某种边界,不同的是进程定义的是应用程序与应用程序之间的边界,不同的进程之间不能共享代 码和 ...
- python平台跨平台开发
有助于跨平台开发的 os 模块属性: linesep 用于在文件中分隔行的字符串 sep 用来分隔文件路径名的字符串 pathsep 用于分隔文件路径的字符串 curdir 当前工作目录的字符串 ...
- PL/SQL Developer 和 instantclient客户端安装配置(图文)
一: PL/SQL Developer 安装 下载安装文件安装,我这里的版本号是PLSQL7.1.4.1391,安装目录是:D:\soft\PLSQLDeveloper 二:instantclient ...