Charm Bracelet
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
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[] ;
int main() {
// freopen("a.txt" , "r" , stdin ) ;
int w[] , D[] ;
int M ;
int n ; int result = ;
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] ) ;
}
}
result = - ;
for (int i = ; i <= M ; i++ ) {
if ( result < dp[i] )
result = dp[i] ;
// printf ("%d " , dp[i] ) ;
} printf("%d\n" , result ) ;
}
return ;
}
01背包
Charm Bracelet的更多相关文章
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)
Charm Bracelet POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...
- D - Charm Bracelet 背包问题
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pra ...
- 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: 38909 Accepted: 16862 ...
- Poj3624 Charm Bracelet (01背包)
题目链接:http://poj.org/problem?id=3624 Description Bessie has gone to the mall's jewelry store and spie ...
- [转]POJ3624 Charm Bracelet(典型01背包问题)
来源:https://www.cnblogs.com/jinglecjy/p/5674796.html 题目链接:http://bailian.openjudge.cn/practice/4131/ ...
- 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 ...
- Charm Bracelet(01背包问题)
题目链接: https://vjudge.net/problem/POJ-3624 题目描述: Bessie has gone to the mall's jewelry store and spie ...
随机推荐
- Jetty嵌入式Web容器攻略
Jetty是一个用 Java 实现.开源.基于标准的,并且具有丰富功能的 Http 服务器和 Web 容器.Jetty中应用最广泛的一项功能就是可以作为嵌入式Web容器. 在开发阶段,可以使用Jett ...
- 开源搜索引擎Iveely 0.8.0发布,终见天日
这是一篇博客,不是,这是一篇开源人的心酸和喜悦,没有人可以理解我们的心情,一路的辛酸一路的艰辛,不过还好,在大家的支持下,总算是终见天日,谢谢那些给予我们无私帮助的朋友.您的支持,依然是我们无限的动力 ...
- KMP和扩展KMP
文章网上太多这里提一下代码细节: KMP: scanf("%s\n",s); scanf("%s\n",t); int ls=strlen(s),lt=strl ...
- Spring 事务配置管理,简单易懂,详细 [声明式]
Spring 事务配置说明 Spring 如果没有特殊说明,一般指是跟数据存储有关的数据操作事务操作:对于数据持久操作的事务配置,一般有三个对象,数据源,事务管理器,以及事务代理机制: Spring ...
- AngularJS-MVC
前言: 编程是一个很苦恼的工作,因为需要我们不断的去学习,不断的去专研,我本身就不是一个很喜欢学习的孩子,要不然从小到大也没有成绩好过,但是,我从来没有缺少过勤奋,还是让我们言归正传来说下 我们这段时 ...
- WRONGTYPE Operation against a key holding the wrong kind of value
今天改动代码,一运行就跑错了,错误原因: 因为redis中已经存在了相同的key, 而且key对应的值类型并不是Set,而是SortSet(改动前):再调用smembers时,抛出此错误. 解决方法: ...
- UVA5876 Writings on the Wall 扩展KMP
扩展KMP的简单题. #include<stdio.h> #include<string.h> #define maxn 51010 char s[maxn],t[maxn]; ...
- Statement,PreparedStatement和CallableStatement的联系和区别
联系: CallableStatement继承自PreparedSatement,PreparedStatement继承自Statement. 区别: 1:Statement 每次执行sql语句,数据 ...
- 【Gym 100685J】Just Another Disney Problem(交互/排序)
第一次做交互题. 题意是有n个数(n<1000),你通过问1 a b,后台返回你YES代表a<b,NO代表a>b.要你在10000次询问内给出一个符合的排列.n=1000来说,100 ...
- 判断一个数据是否存在于一个表中,Oracle中写自定义函数
create or replace function isExist(data in DataTypes) --DataTypes 为表中该数据的类型return Numberisv_flag num ...