Charm Bracelet
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 30417   Accepted: 13576

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
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int MAXN=;
int dp[];
int n,W;
int v[MAXN],w[MAXN];
int main()
{
while(scanf("%d%d",&n,&W)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<n;i++) scanf("%d%d",&w[i],&v[i]); for(int i=;i<n;i++)
{
for(int j=W;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
printf("%d\n",dp[W]);
} return ;
}

POJ3624(01背包:滚动 实现)的更多相关文章

  1. POJ3624 0-1背包(dp+滚动数组)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 47440   Accepted: 20178 ...

  2. UVA - 12563 Jin Ge Jin Qu hao(劲歌金曲)(0-1背包+滚动数组)

    题意:在KTV唱歌剩下的t秒时间内,决定选最爱的n首歌中的一部分歌,在时间结束之前唱一首时长678秒的<劲歌金曲>,使得唱的总曲目尽量多(包括<劲歌金曲>),在此前提下尽量晚的 ...

  3. 算法笔记(c++)--关于01背包的滚动数组

    算法笔记(c++)--关于01背包的滚动数组 关于01背包问题:基本方法我这篇写过了. https://www.cnblogs.com/DJC-BLOG/p/9416799.html 但是这里数组是N ...

  4. codeforces 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses ——(01背包变形)

    题意:给你若干个集合,每个集合内的物品要么选任意一个,要么所有都选,求最后在背包能容纳的范围下最大的价值. 分析:对于每个并查集,从上到下滚动维护即可,其实就是一个01背包= =. 代码如下: #in ...

  5. Codeforces 741B:Arpa's weak amphitheater and Mehrdad's valuable Hoses(01背包+并查集)

    http://codeforces.com/contest/741/problem/B 题意:有 n 个人,每个人有一个花费 w[i] 和价值 b[i],给出 m 条边,代表第 i 和 j 个人是一个 ...

  6. Uva 12563,劲歌金曲,01背包

    题目链接:https://uva.onlinejudge.org/external/125/12563.pdf 题意:n首歌,每首歌的长度给出,还剩 t 秒钟,由于KTV不会在一首歌没有唱完的情况下切 ...

  7. UVA 12563 劲歌金曲(01背包)

    劲歌金曲 [题目链接]劲歌金曲 [题目类型]01背包 &题解: 题意:求在给定时间内,最多能唱多少歌曲,在最多歌曲的情况下,使唱的时间最长. 该题类似于01背包问题,可用01背包问题的解题思路 ...

  8. HDu 3449 (有依赖的01背包) Consumer

    题意: 有n件物品,对应有不同的价格和价值,这是典型的01背包.但现在有了一个限制,要买物品先买能装这件物品的特定的盒子,盒子的价值为0 代码理解得还不是太好,感觉这是一个“二重”的01背包.首先假设 ...

  9. hihocoder 1038 01背包

    #1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...

随机推荐

  1. myeclipse2014破解

    去年出现的struts2 bug问题,在过去的项目中一直没做调整,前段时间发现受到影响了.本想这个bug都已经这么长时间了,工具中的包应该也已经被替换了吧,于是下载了最新的myeclipse2014, ...

  2. ubuntu boot空间不足

    在安装 Ubuntu的时候 , 给/boot文件目录分配空间的时候,是100M,/boot可以单独分成一个区,也可以不单独分,在/(根目录)下也会自动为其创建一个boot目录.顺便提一下,Linux分 ...

  3. android handler looper

    http://www.cnblogs.com/plokmju/p/android_Handler.html

  4. LeetCode(83)题解: Remove Duplicates from Sorted List

    https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 题目: Given a sorted linked list, de ...

  5. Linux 如何搭建Lamp的服务环境

    在介绍虚拟机的安装使用之前,我们先认识一下LINUX中LAMP是什么的缩写 L--Linux   A--Apache   M--Mysql  P--PHP 虚拟机的安装百度有详细的介绍,非常简单的,这 ...

  6. centos7设置tomcat7为系统服务的方法

    1,准备工作: JKD:jdk-7u72-Linux-x64.gz Tomcat:apache-tomcat-7.0.70.tar.gz OS:CentOS linux release 7.2.151 ...

  7. Python3做采集

    出于某些目的,需要在网上爬一些数据.考虑到Python有各种各样的库,以前想试试Pycharm这个IDE,就决定用它了.首先翻完<深入Python3>这本书,了解了它的语法之类的.下面就开 ...

  8. 基于EasyIPCamera实现的RTSP跨平台拉模式转发流媒体服务器

    本文转自博客:http://blog.csdn.net/xinlanbobo/article/details/53224445 上一篇博客<EasyIPCamera通过RTSP协议接入海康.大华 ...

  9. WEBRTC开发入门

    WEBRTC "WebRTC,名称源自网页实时通信(Web Real-Time Communication)的缩写,是一个支持网页浏览器进行实时语音对话或视频对话的技术,是谷歌2010年以6 ...

  10. vue web开发

    https://www.szzhdj.gov.cn/js/pagejs/assemblyHall_dzs1.js https://www.szzhdj.gov.cn/js/pagejs/assembl ...