http://poj.org/problem?id=3624

Charm Bracelet
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 29444   Accepted: 13198

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

这个是简单的01背包   从我开始接触到背包到现在我还是不懂背包的原理 
开始背包的旅程
正常的背包是
i 1....n
j m....0
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
但是这个范围较大
如果用二维的会超内存
可以转化成一维的
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream> using namespace std; #define N 3500
int dp[]; int main()
{
int n,m,w[N],v[N];
while(scanf("%d %d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d %d",&w[i],&v[i]);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
for(int j=m;j>=;j--)
{
if(j>=w[i])
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
printf("%d\n",dp[m]);
}
return ;
}
 

Charm Bracelet-POJ3624(01背包)的更多相关文章

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

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

  2. POJ3624 Charm Bracelet 【01背包】

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22621   Accepted: 10157 ...

  3. Poj3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Description Bessie has gone to the mall's jewelry store and spie ...

  4. poj 3524 Charm Bracelet(01背包)

    Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd ...

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

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

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

  7. Charm Bracelet(01背包)

    Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...

  8. poj 3624 Charm Bracelet(01背包)

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

  9. P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)

    题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...

  10. POJ 3624 Charm Bracelet 简单01背包

    题目大意:有n件珠宝,每个珠宝的魅力值为v,重量为w,求在重量不超过m的情况下能达到的最大魅力值. 题目思路:简单的01背包,由于二维数组会超内存所以应该压缩成一维数组. dp[i][j],表示选取i ...

随机推荐

  1. Mac 为啥不显示图片尺寸,点了显示简介也不显示~???

    这个问题困扰我好几天,然后今天想法子解决,我这个强迫症患者是真的难受,不能直接一目了然的,每次都要ps打开图片去看,真的好心累???? 网上98%的解决方法如下: 在 Finder 中,按快捷键 co ...

  2. Android 在代码中安装 APK 文件

    废话不说,上代码 private void install(String filePath) { Log.i(TAG, "开始执行安装: " + filePath); File a ...

  3. 新浪qq登录

    一:到腾讯QQ互联上申请APPID和APPKEY.申请地址: http://connect.qq.com/ 如同,这里我们可以获取到需要跳转到的APPID和APPKEY.新浪微博的申请同理 二:在Th ...

  4. 关于Android软键盘把布局顶上去的问题

    首先说下我的需求:布局最上面是一个bar,有左上角返回按钮和标题,bar下面是一个ScrollView,里面有各种TextView和EditText, 点击下面的EditText时,不希望软键盘把ba ...

  5. jsp 页面获取当前路径

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  6. H.264学习笔记6——指数哥伦布编码

    一.哥伦布码 哥伦布码就是将编码对象分能成等间隔的若干区间(Group),每个Group有一个索引值:Group Id. >对于Group Id采用二元码编码: >对于Group内的编码对 ...

  7. Jvisualvm--JAVA性能分析工具

    JDK自带的JAVA性能分析工具.它已经在你的JDK bin目录里了,只要你使用的是JDK1.6 Update7之后的版本.点击一下jvisualvm.exe图标它就可以运行了. 这里是VisualV ...

  8. Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图的数据操作

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射 下一篇:Farseer.net轻量级ORM开源 ...

  9. Java调用WebService接口实现发送手机短信验证码功能,java 手机验证码,WebService接口调用

    近来由于项目需要,需要用到手机短信验证码的功能,其中最主要的是用到了第三方提供的短信平台接口WebService客户端接口,下面我把我在项目中用到的记录一下,以便给大家提供个思路,由于本人的文采有限, ...

  10. Redux的中间件Middleware不难,我信了^_^

    Redux的action和reducer已经足够复杂了,现在还需要理解Redux的中间件.为什么Redux的存在有何意义?为什么Redux的中间件有这么多层的函数返回?Redux的中间件究竟是如何工作 ...