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 ...
随机推荐
- android之显示数据库信息
关键字 ListView adapter MVC 在android开发中也使用到了MVC架构,其中的xml布局文件就是V,M就是我们定义好的javabean类,而控制器就是就是适配器类adapter ...
- 编写高质量代码改善C#程序的157个建议[4-9]
前言 本文首先亦同步到http://www.cnblogs.com/aehyok/p/3624579.html.本文主要来学习记录一下内容: 建议4.TryParse比Parse好 建议5.使用int ...
- 9、面向对象以及winform的简单运用(输入输出流、图像的上传和读取)
一.输入输出流 1.概念: 输入输出流主要用于保存.读取文件,其内容保存在内存中. 2.使用方法: using System.IO; //System.IO 命名空间包含允许读写文件和数据流的类型以及 ...
- Xdebug开源PHP程序调试器
Xdebug是一个开放源代码的PHP程序调试器(即一个Debug工具),可以用来跟踪,调试和分析PHP程序的运行状况. 本文为大家讲解的是在linux下xdebug的安装和配置方法,感兴趣的同学参考下 ...
- Linux下安装项目管理工具Redmine
http://www.redmine.org.cn/download Linux下安装项目管理工具Redmine1.Ruby安装Ruby on Rails网站推荐使用1.8.7版. 点击(此处)折叠或 ...
- Qt无边框,可移动窗口
QPoint dragPosition; void MainWindow::mousePressEvent(QMouseEvent *event) { if(event->button()==Q ...
- hdu1025 最长上升子序列 (nlogn)
水,坑. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm&g ...
- Java 工程师的学习线路图。
今天了一个超级好用的工具,思维导图 FreeMind,于是顺道试用了一下,照着画了一张 Java 工程师的学习线路图.
- Java-人民币转成大写
/** * 人民币转成大写 hangeToBig * * @param value * @return String */ public static String 人民币转成大写(double va ...
- JEECMS插件开发
在jeecms框架中,有一个简单的插件,它并没有写具体的功能实现,但可以从这个简单的插件中找到如何在jeecms框架中开发框架的方法. 首先创建一个jeecms的框架demo,登录jeecm ...