Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 47876   Accepted: 20346

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<cstdio>
using namespace std;
const int N=;
int maxx(int x,int y){
return x>y?x:y;
} int main(){
int n,m,i,j;
int w[N],p[N];
while(~scanf("%d%d",&n,&m)){
int c[]={};
for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&p[i]);
for(int i=;i<=n;i++)
for(int j=m;j>=w[i];j--)
c[j]=maxx(c[j],c[j-w[i]]+p[i]);
printf("%d\n",c[m]);
}
return ;
}

POJ 3624.Charm Bracelet-动态规划0-1背包的更多相关文章

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

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

  2. 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 ...

  3. poj 3624 Charm Bracelet 背包DP

    Charm Bracelet Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ...

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

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

  5. POJ 3624 Charm Bracelet(01背包)

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

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

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 45191   Accepted: 19318 ...

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

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

  8. poj 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29295   Accepted: 13143 ...

  9. poj 3624 Charm Bracelet 01背包问题

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

  10. POJ 3624 Charm Bracelet

    DP 一直是心中痛,不多说了,这个暑假就坑在这上了. 这暑假第一道DP题,01背包问题. 题意是说物品有 重量和价值 ,但你能承受的重量有限,问你能带的最大价值. 这题数组开大点,尽管不知道有啥坑点, ...

随机推荐

  1. KVO的底层实现原理?如何取消系统默认的KVO并手动触发?

    KVO是基于runtime机制实现的 当某个类的属性对象第一次被观察时,系统就会在运行期动态地创建该类的一个派生类(该类的子类),在这个派生类中重写基类中任何被观察属性的setter 方法.派生类在被 ...

  2. Pascal小游戏 俄罗斯方块怀旧版

    俄罗斯方块怀旧版(注释版) {$APPTYPE GUI}{$MODE DELPHI}program WinPiece; usesWindows; constAppName = 'WinPiece';p ...

  3. shell脚本递归删除空文件夹

    有时我们需要递归删除空文件夹,网上找了一下,没有发现比较好的脚本,于是自己动手写了一个 脚本 #!/bin/bash # author: 十年后的卢哥哥(http://www.cnblogs.com/ ...

  4. Velocity 语法详解

    Velocity是基于Java的模板引擎,它允许页面设计者引用Java中定义的方法.页面设计者和Java开发者能够同时使用MVC的模式开发网站,这样网页设计者能够把精力放在页面的设计上,程序员也可以把 ...

  5. 每天一个Linux命令(9):cp命令

    cp命令用来将一个或多个源文件或者目录复制到指定的目的文件或目录.它可以将单个源文件复制成一个指定文件名的具体的文件或一个已经存在的目录下.cp命令还支持同时复制多个文件,当一次复制多个文件时,目标文 ...

  6. iframe 如何让它展现内容自适应高度

    引用: <iframe id="ifm1" runat="server" src="/comment/page1?id=@productId&q ...

  7. [译]15-spring 自动装配

    前面的章节我们已经学习了如何使用bean元素在xml配置文件中声明一个bean.也学习了如何使用bean的子元素contructor-arg 和property进行bean的依赖项的注入. 之前bea ...

  8. mysql中查询常用的关键字

    最简单的查询: 1 select * from [where ] 1 select column1,column2....from [where] 这里需要注意的是where子句中条件过滤使用到的关键 ...

  9. jQuery Ajax(load,post,get,ajax)

    1.load(url, [data], [callback]) 载入远程 HTML 文件代码并插入至 DOM 中. 默认使用 GET 方式 - 传递附加参数时自动转换为 POST 方式.jQuery ...

  10. Scala 基础(8)—— 占位符_和部分应用函数

    1. 占位符 _ 针对 Scala 基础(7)—— 函数字面量和一等函数 中最后提到的,关于 filter 函数字面量的精简写法,可以使用占位符 _ 来代替. 占位符_,用来表示一个或者多个参数.(这 ...