poj 3624 Charm Bracelet(01背包)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 29295 | Accepted: 13143 |
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 <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,m,i,j;
int a[],b[];
while(~scanf("%d%d",&n,&m))
{
for(i=; i<n; i++)
scanf("%d%d",&a[i],&b[i]);
int dp[]; //dp数组的大小wa了一次,要注意必须和最大重量相同,而不是最大珠子个数
memset(dp,,sizeof(dp));
for(i=; i<n; i++)
for(j=m; j>=a[i]; j--)
dp[j]=max(dp[j],dp[j-a[i]]+b[i]); //比较加上这颗珠子和不加的价值谁更大,记录大的那个
printf("%d\n",dp[m]);
}
return ;
}
poj 3624 Charm Bracelet(01背包)的更多相关文章
- 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 0-1背包
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...
- POJ 3624 Charm Bracelet(01背包模板题)
题目链接 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52318 Accepted: 21912 Descriptio ...
- poj 3624 Charm Bracelet 01背包问题
题目链接:poj 3624 这是最基础的背包问题,特点是:每种物品仅有一件,可以选择放或不放. 用子问题定义状态:即F [i, v]表示前i件物品恰放入一个容量为v 的背包可以 ...
- 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(0-1背包模板)
http://poj.org/problem?id=3624 题意:给出物品的重量和价值,在重量一定的情况下价值尽可能的大. 思路:经典0-1背包.直接套用模板. #include<iostre ...
- POJ 3624 Charm Bracelet(01背包模板)
Charm Bracelet Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45191 Accepted: 19318 ...
随机推荐
- GDOI2017第二轮模拟day1 总结
平民比赛 这场比赛的暴力分非常友好. 但是我并没有拿到全部的暴力分. 1(暴力分\(60/100\)) 暂时我可以拿的暴力分为\(30/100\),直接mst模拟即可. 然而当时打了个辣鸡莫队,结果爆 ...
- JS函数式编程 - 概念
最近在看Typescript,顺便看了一些函数式编程,然后半个国庆假期就没有了.做个笔记,分几个部分写吧. 最开始接触函数式编程的时候,第一个接触的概念就是高阶函数,和柯里化.咋一看,这不就是长期用来 ...
- vue 根据数组中某一项的值进行排序
一.前言 我在vue项目中遇到了一个表格排序的需求,根据某一项的值的大小从大到小调整数组顺序. 二.代码 表格大概是这个样子,样式和图片在代码中简化了. <table class="r ...
- php封装的smarty类实例是怎样
* @link http://www.smarty.net/* @copyright 2008 New Digital Group, Inc.* @author Monte Ohrt <mont ...
- JavaScript--封装好的运动函数+旋转木马例子
封装好的运动函数: 1.能控制目标元素的多种属性 2.能自动获取元素的样式表: 3.获取样式函数兼容 4.能对于元素的多属性进行动画(缓动动画)修改 5.能区分透明度等没单位的属性和px属性的变化 a ...
- Ubuntu16.04安装Caffe最全最详细教程(CPU)
转载请附上本文链接:https://www.cnblogs.com/acgoto/p/11570188.html 一.前言 为了安装caffe,本人已经在centos7.x上试错了1次,目前弃疗~:在 ...
- nodeJs学习-19 个人博客案例-(1)数据字典
智能社视频27.28 数据字典: 定义: url 300字 admin_table 管理员用户表 ID username varchar(32) password varchar(32) banner ...
- Java安全——密钥那些事
标签(空格分隔): Java 安全 概念 密钥是加密算法不可缺少的部分.密钥在安全体系中至关重要,正如其名,私密的钥匙,打开安全的大门.密钥分两种:对称密钥和非对称密钥.非对称密钥里又包含公开密钥和私 ...
- Failed to delete access_log
重复build 关闭已经开启的tomcat terminal 再次开启即可
- oracle如何启用审计
通过数据库初始化参数文件中的AUDIT_TRAIL 初始化参数启用和禁用数据库审计. DB 启用数据库审计并引导所有审计记录到数据库的审计跟踪 OS 启用数据库审计并引导所有审计记录到操作系统的审 ...