POJ 3624 Charm Bracelet(01背包裸题)
Charm Bracelet
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 38909 | Accepted: 16862 |
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
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int w[],d[],dp[];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&d[i]);
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背包模板题)
题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ...
- POJ 3624 Charm Bracelet 0-1背包
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...
- POJ 3624 Charm Bracelet(01背包)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ...
- 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 背包DP
Charm Bracelet Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ...
- HDU 2602 Bone Collector(01背包裸题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 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 ...
随机推荐
- 【java】System成员输入输出功能out、in、err
package System输入输出; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOu ...
- 谈谈对Python的感想
写在前面 我用Python已经好几年了,最早学习用Python还是因为对人工神经网络感兴趣,python有个很好用的ANN库neurolab.本人其实也算初学者,充其量算入门了吧,写这篇一来回顾自己所 ...
- 599. Minimum Index Sum of Two Lists
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...
- c#加密解密源码,md5、des、rsa
从网上找来的代码,顺手改改,用起来更方便. 配置文件 using System; using System.Collections.Generic; using System.Text; using ...
- Android模拟器
一.Genymotion 1.下载安装:https://www.genymotion.com/download/ (注:安装前需要先注册) 因为Genymotion运行需要VirtualBox,如果 ...
- springMVC(5)---导入excel文件数据到数据库
springMVC(5)---导入excel文件数据到数据库 上一篇文章写了从数据库导出数据到excel文件,这篇文章悄悄相反,写的是导入excel文件数据到数据库.上一篇链接:springMVC(4 ...
- fastq,sam文件一些小结(持续补充。。。)
ST-E00211::H5L3NCCXY:::: chr14 141M = - ACTTCACCTCCTGGAGTCCTGGACTTCCCCACATCTCCCCTGCCCCTCCCACGTTTCCAT ...
- 高效的CSS代码(2)
——阅读笔记,欢迎纠错^_^ 内容比较零散..... 1.让浮动元素的父容器根据元素的高度而自适应高度的方法: <div class="clearfix"><di ...
- JavaScript 浏览器类型及版本号
项目中偶尔用到判断浏览器类型及相关版本问题,现记录相关代码: function getBrowserVertion(userAgent) { var browserName, browserVersi ...
- 【读书笔记】【深入理解ES6】#11-Promise与异步编程
异步编程的背景知识 JavaScript 引擎是基于单线程(Single-threaded)实际循环的概念构建的,同一时刻只允许一个代码块在执行. 所以需要跟踪即将运行的代码,那些代码被放在一个任务队 ...