POJ - 3624

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

Submit
Status

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<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[100100];
struct node
{
int w,val;
}edge[100100];
int main()
{
int m,n;
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(dp,0,sizeof(dp));
for(int i=0;i<m;i++)
scanf("%d%d",&edge[i].w,&edge[i].val);
for(int i=0;i<m;i++)
for(int j=n;j>=edge[i].w;j--)
dp[j]=max(dp[j],dp[j-edge[i].w]+edge[i].val);
printf("%d\n",dp[n]);
}
return 0;
}


FAQ | About Virtual Judge | Forum | Discuss | Open Source Project

All Copyright Reserved ©2010-2014 HUST ACM/ICPC TEAM

Anything about the OJ, please ask in the forum, or contact author:Isun

Server Time: 2015-10-14 17:57:36

poj--3624--Charm Bracelet(动态规划 水题)的更多相关文章

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

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

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

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

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

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

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

  5. poj 3624 Charm Bracelet 背包DP

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

  6. POJ 3624 Charm Bracelet(01背包)

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

  7. poj 3624 Charm Bracelet 01背包问题

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

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

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

  9. poj 3624 Charm Bracelet(01背包)

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

  10. POJ 3624 Charm Bracelet 0-1背包

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

随机推荐

  1. ES6 Template String 模板字符串

    模板字符串(Template String)是增强版的字符串,用反引号(`)标识,它可以当作普通字符串使用,也可以用来定义多行字符串,或者在字符串中嵌入变量. 大家可以先看下面一段代码: $(&quo ...

  2. P1375 嵌套矩形

    题目Problem 嵌套矩形 Time Limit: 1000ms    Memory Limit: 131072KB 描述Descript. 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形 ...

  3. halcon 模板匹配 -- 转化 vector_angle_to_rigid

    ********************************模板匹配 ********************create_shape_model创建模板,这个函数有许多参数,其中金字塔的级数由N ...

  4. ROS:ubuntuKylin17.04-Ros使用OrbSLAM2

    忙于图像处理和DCNN,很长时间不使用ROS,重新安装系统后,再次使用ORB-SLAM2(ROS)进行三维重建和实时追踪的演示. 参考以前的文章:ROS:ubuntu-Ros使用OrbSLAM ORB ...

  5. 解决JavaOpenCV的内存问题

    在使用OpenCV时,程序总是在某个时间墨明棋妙地终止,打开CygWin ,输入 adb logcat ,查看打印的信息,发现是内存问题.经过反复的查找,发现使用OpenCV的java类库时,一定要慎 ...

  6. java这个404你能解决吗?

    前言 本文首发于公众号[我的小碗汤]本公众号免费提供csdn下载服务,海量IT学习资源,如果你准备入IT坑,励志成为优秀的程序猿,那么这些资源很适合你,包括但不限于java.go.python.spr ...

  7. canvas画弧线

    arc(x, y, radius, startRad, endRad, [anticlockwise]) 在Canvas画布上绘制以坐标点(x,y)为圆心.半么为radius的圆上的一段弧线.这段弧线 ...

  8. Js 删除前弹出确认框

    <td align="center" valign="middle" class="black3"> <c:if test ...

  9. JavaScript中原生事件

    DOM0事件模型: 所有浏览器都支持,只能注册一种事件 1.绑定: document.getElementById("id").onclick = function(e){}; 解 ...

  10. Day 25 面向对象

    面向对象基础 面向对象编程 面向过程编程:类似于工厂的流水线 优点:逻辑清晰 缺点:扩展性差 面向对象编程:核心是对象二字,对象属性和方法的集合体,面向对象编程就是一堆对象交互 优点:扩展性强 缺点: ...