POJ 3624.Charm Bracelet-动态规划0-1背包
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 47876 | Accepted: 20346 | 
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<cstdio>
using namespace std;
const int N=;
int maxx(int x,int y){
return x>y?x:y;
} int main(){
int n,m,i,j;
int w[N],p[N];
while(~scanf("%d%d",&n,&m)){
int c[]={};
for(int i=;i<=n;i++)
scanf("%d%d",&w[i],&p[i]);
for(int i=;i<=n;i++)
for(int j=m;j>=w[i];j--)
c[j]=maxx(c[j],c[j-w[i]]+p[i]);
printf("%d\n",c[m]);
}
return ;
}
POJ 3624.Charm Bracelet-动态规划0-1背包的更多相关文章
- POJ.3624 Charm Bracelet(DP 01背包)
		POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ... 
- 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 ... 
- poj 3624 Charm Bracelet 背包DP
		Charm Bracelet Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3624 Descripti ... 
- POJ 3624 Charm Bracelet(01背包裸题)
		Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 38909 Accepted: 16862 ... 
- POJ 3624 Charm Bracelet(01背包)
		Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34532 Accepted: 15301 ... 
- POJ 3624 Charm Bracelet(01背包模板)
		Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45191 Accepted: 19318 ... 
- POJ 3624 Charm Bracelet(01背包模板题)
		题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ... 
- poj 3624 Charm Bracelet(01背包)
		Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 29295 Accepted: 13143 ... 
- poj 3624 Charm Bracelet 01背包问题
		题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. 用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ... 
- POJ 3624 Charm Bracelet
		DP 一直是心中痛,不多说了,这个暑假就坑在这上了. 这暑假第一道DP题,01背包问题. 题意是说物品有 重量和价值 ,但你能承受的重量有限,问你能带的最大价值. 这题数组开大点,尽管不知道有啥坑点, ... 
随机推荐
- Eclipse 修改字符集---Eclipse教程第02课
			默认情况下 Eclipse 字符集为 GBK,但现在很多项目采用的是 UTF-8,这是我们就需要设置我们的 Eclipse 开发环境字符集为 UTF-8, 设置步骤如下: 在菜单栏选择 Window ... 
- C++ Primer 第2章 变量和基本类型
			C++ Primer 第2章 变量和基本类型 C Primer 第2章 变量和基本类型 1 基本内置类型 算数类型 类型转换 字面值常量 2 变量 变量定义 3 复合类型 引用d左引用 指针d 4 c ... 
- 第九章 广播和本地组播(IGMP和MLD)
			距离项目开启已经过去了一段时间,这段时间内自己学习的内容也算挺多的,但是也较容易遗忘,之后应该在空余的时间内多翻翻博客,更加清楚传统计算机网络的运作. 由于51要出去玩,更要好好利用好最近的时间.完成 ... 
- Python 3.x的编码问题
			Python 3的源码.py文件的默认编码方式为UTF-8(Python 2.x的默认编码格式为unicode). encode的作用,使我们看到的直观的字符转换成计算机内的字节形式. decode刚 ... 
- ComboBox列表自定义类保存数据
			之前没弄明白ComboBox还可以这样用. 先建一个ComboBox子项类,然后可以获取该项类做一些判断,关键是要重写ToString()方法. public class ComboItem { pu ... 
- aes加密码
			js地址 https://github.com/yves8888/crypto-js 下面src<!DOCTYPE html> <html lang="en"&g ... 
- Crash的游戏 [组合+递推]
			题面 思路 问题转化 这个问题的核心在于,我们需要把"加入一个球.拿出一个球"这两个操作转化一下 因为显然两个操作同时进行的话,我们没有办法从单纯的组合意义去分析 我们首先把$m$ ... 
- BZOJ 1861: [Zjoi2006]Book 书架 | SPlay 板题
			#include<cstdio> #include<algorithm> #include<cstring> #define N 80010 #define whi ... 
- flex弹性布局的基本介绍
			最近开始做元素排列比较复杂的项目,同时需要各种型号手机的适配,我发现以前所掌握的盒子模型.display.position.float等已经不能满足我的需求了, 于是开始着重学习flex弹性布局并运用 ... 
- php curl模块开启失败解决参考
			现在公司的测试项目和正式项目是部署在同一台服务器上的,为了在重启apache时互不影响,我在服务器上部署了两个apache服务,使用nginx做url转发. 结果正式环境的项目使用curl没有问题,但 ... 
