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. 【Arduino】LCD 1602 转接板 的默认接线

    原来的1602屏需要7个IO口才能驱动起来LCD 1602转接板可以帮你省5个IO口. 在Arduino中,LCD 1602 转接板可以使用函数库LiquidCrystal_I2C1602: 该函数的 ...

  2. 后端springmvc,前端html5的FormData实现文件断点上传

    前言 最近项目中有使用到文件断点上传,得空便总结总结,顺便记录一下,毕竟“好记性不如烂笔头”. 后端代码: package com.test.controller; import java.io.Bu ...

  3. Leetcode0019--Remove Nth Node From End of List 移除链表第N个结点

    [转载请注明]http://www.cnblogs.com/igoslly/p/8672656.html 看一下题目: Given a linked list, remove the nth node ...

  4. YOLO (You Only Look Once)

    YOLO (You Only Look Once) dl  cnn  object detection  一.YOLO YOLO是一个实时的目标检测系统.最新的V2版本在Titan X 上可以每秒处理 ...

  5. CDC之Metastability

    1 CDC  A clock domain crossing occurs whenever data is transferred from a flop driven by one clock t ...

  6. 三维重建:SFM中BA的并行化

    1. BA在重建中的作用 借鉴于运动中重建的方法,BA引入SLAM过程,而传统的滤波方法引入BA是跟随闭环检测出现. 1.1 BA在滤波方法中的嵌入 PTAM 1.2 BA在闭环检测之后的应用 在三维 ...

  7. 在 ef 中执行 DbContext.Table.AddRange(Enitites).ToList() 会发生什么

    在 ef 中执行 DbContext.Table.AddRange(Enitites).ToList() 会发生什么 昨天和朋友摸鱼,无意之间聊到了执行 DbContext.Table.AddRang ...

  8. swift-UITableView的基本使用

    废话不多说了,直接贴我今天写的代码吧:如果新手有什么不懂的,可以发我邮箱. // //  singleInfo.swift            个人信息 //  Housekeeper // //  ...

  9. 继续聊WPF——为ListView的行设置样式

    <Window x:Class="Wpf_GridHeaderStyle_sample.Window1" xmlns="http://schemas.microso ...

  10. h264封包介绍

    这个要看你怎么理解了.和MPEG2.MPEG4相比,H.264字节流中帧的形式发生了变化.以视频帧为例,MPEG2和MPEG4字节流在传输的时候提取帧的关键参数,将其封装入传输包首部,比如TS包或RT ...