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. Cannot find module 'crc'

    这个时候你只需要打开你nodejs安装的目录,在其中执行 npm install crc(这里查什么模块(module)就安装什么模块).

  2. VMware中linux安装jdk

    首先安装linux系统 如何将jdk安装包复制到linux中不做概述,可以使用xftp工具,或者Xshell,或者其他方式. 1.下载jdk包:本章使用的为后缀为tar.gz的文件(不需要安装),如j ...

  3. 与swift协议相关的技术

    一.协议定义与实现: 1.关联类型: 2.协议组合: 3.协议扩展: 4.协议实现. 二.协议使用:

  4. Jenkins构建项目

    创建项目 Jenkins版本:Jenkins ver.2.150.1 在Jenkins首页点击‘New 任务’进入创建任务页面,在‘Enter an item name’输入框内输入项目名称,选择Je ...

  5. 平衡二叉树(Self-balancing Binary Search Tree)

    Date: 2019-04-11 18:49:18 AVL树的基本操作 //存储结构 struct node { int data; int height; //记录当前子树的高度(叶子->根) ...

  6. Day 2 语言元素

    1.变量和类型 在程序设计中,变量是一种存储数据的载体.计算机中的变量是实际存在的数据或者说是存储器中存储数据的一块内存空间,变量的值可以被读取和修改,这是所有计算和控制的基础.计算机能处理的数据有很 ...

  7. Mark Zuckberg: A letter to our daughter

    转自:   http://www.fastcompany.com/3054120/fast-feed/read-mark-zuckerbergs-letter-to-his-newborn-daugh ...

  8. Linux思维导图之查找命令

    常用查找命令的区别:

  9. 利用IO多路复用,使用linux下的EpollSelector实现并发服务器

    import socket import selectors # IO多路复用选择器的模块 # 实例化一个和epoll通信的选择器 epoll_selector = selectors.EpollSe ...

  10. 【2000*】【Codeforces Round #518 (Div. 1) [Thanks, Mail.Ru!] B】Multihedgehog

    [链接] 我是链接,点我呀:) [题意] [题解] 找到度数为1的点. 他们显然是叶子节点. 然后每个叶子节点. 往上进行bfs. 累计他们的父亲节点的儿子的个数. 如果都满足要求那么就继续往上走. ...