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

//依然是01背包基础题
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int value[],volume[],dp[]; int main()
{
int n,v;
while(cin>>n>>v)
{
for(int i=;i<=n;i++)
cin>>volume[i]>>value[i];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
for(int j=v;j>=volume[i];j--)
dp[j]=max(dp[j],dp[j-volume[i]]+value[i]);
cout<<dp[v]<<endl;
}
return ;
}

poj 3524 Charm Bracelet(01背包)的更多相关文章

  1. POJ 3624 Charm Bracelet(01背包裸题)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38909   Accepted: 16862 ...

  2. POJ 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 34532   Accepted: 15301 ...

  3. POJ 3624 Charm Bracelet 0-1背包

    传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...

  4. POJ 3624 Charm Bracelet(01背包模板题)

    题目链接 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 52318   Accepted: 21912 Descriptio ...

  5. 洛谷——2871[USACO07DEC]手链Charm Bracelet——01背包

    题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...

  6. 洛谷 P2871 [USACO07DEC]手链Charm Bracelet && 01背包模板

    题目传送门 解题思路: 一维解01背包,突然发现博客里没有01背包的板子,补上 AC代码: #include<cstdio> #include<iostream> using ...

  7. poj 3624 Charm Bracelet 01背包问题

    题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放.             用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...

  8. poj3642 Charm Bracelet(0-1背包)

    题目意思: 给出N,M,N表示有N个物品,M表示背包的容量.接着给出每一个物品的体积和价值,求背包可以装在的最大价值. http://poj.org/problem? id=3624 题目分析: o- ...

  9. POJ.3624 Charm Bracelet(DP 01背包)

    POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...

随机推荐

  1. hdu1030

    #include<stdio.h>#include<math.h>void find(int n,int &l,int &r,int &level){ ...

  2. 浙大pat1020题解

    1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  3. PotPlayer播放器 莫尼卡汉化绿色版 V1.6.48089 32位

    软件名称: PotPlayer播放器 莫尼卡汉化绿色版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 10.5MB ...

  4. linux 下执行.sh文件提示permission denied

    linux 下执行.sh文件提示permission denied 在脚本文件目录下运行命令,赋予权限: chmod 777 *.sh or chmod +x  *.sh

  5. 学习node的REPL

    REPL: read eval print loop 支持 多行代码 编辑模式,即 识别{} () 为代码块. 在repl中快速查看 对象的属性 gl = global repl command .h ...

  6. jmeter下载及安装配置

    本文是在win7环境下安装使用jmeter,jmeter可以运行在多平台上Windows和Linux. 前提:使用jmeter工具之前需要安装java.并配置好java的环境变量.(备注:java下载 ...

  7. echart+jquery+json统计TP数据

    由于工作需要,需要统计交易数据的TP50,TP90,TP95,TP99.采用的前端技术是jquery+json+echart. 一.TP定义(谷歌) Calculating TP is very si ...

  8. linux 文件和目录操作

    1 相对路径和绝对路径 (与C++中概念相似) cd /root/cat 绝对路径 cd ../文件名/ 相对路径,指相对某个文件而言的 2 切换目录 cd  当前目录 进入某个目录 pwd 显示当前 ...

  9. apue学习记录——配置apue.3e,实现P4‘ls例子

    #include"apue.h" #include<dirent.h> int main(int argc,char *argv[]) { DIR *dp; struc ...

  10. win7搭建php7+apache2.4

    从事php开发的工作也将近两年的时间了,期间在windows上安装了很多次php+apache+mysql,但一直没有写过一篇属于自己的文章,今天心血来潮准备写一篇,长话短说,开搞!! 我在配置php ...