POJ-3426-0-1背包Charm Bracelet
Charm Bracelet
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
Output
* Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
Sample Input
Sample Output
23
dp[i][v]=max{dp[i-1][v],dp[i-1][v-c[i]]+w[i]}
#include<stdio.h>
#include<string.h>
int main()
{int i,N,M,w[3500],D[3500],dp[13000],j;while(scanf("%d%d",&N,&M)!=EOF){memset(dp,0,sizeof(dp));for(i=1; i<=N; i++){scanf("%d%d",&w[i],&D[i]);}for(i=1; i<=N; i++){for(j=M; j>=0; j--){if(j-w[i]>=0)dp[j]=dp[j]>dp[j-w[i]]+D[i]? dp[j]:dp[j-w[i]]+D[i];elsedp[j]=dp[j];}}printf("%d\n",dp[M]);}}
POJ-3426-0-1背包Charm Bracelet相关推荐
- 【POJ - 3624 】Charm Bracelet (dp,0-1背包裸题)
题干: Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to ...
- POJ 3624 Charm Bracelet
DP 一直是心中痛,不多说了,这个暑假就坑在这上了. 这暑假第一道DP题,01背包问题. 题意是说物品有 重量和价值 ,但你能承受的重量有限,问你能带的最大价值. 这题数组开大点,尽管不知道有啥坑点, ...
- AC日记——[USACO07DEC]手链Charm Bracelet 洛谷 P2871
题目描述 Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like t ...
- 洛谷——P2871 [USACO07DEC]手链Charm Bracelet
https://www.luogu.org/problem/show?pid=2871 题目描述 Bessie has gone to the mall's jewelry store and spi ...
- Charm Bracelet(POJ-3624)
Problem Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of cours ...
- 【Charm Bracelet】题目解析~~
题目: [Charm Bracelet] 有n个物品,编号为i的物品的重量为w[i],价值为c[i],现在要从这些物品中选一些物品装到一个容量为m的背包中,使得背包内物体在总重量不超过m的前提下价值尽 ...
- 信息学奥赛一本通 1294:Charm Bracelet | OpenJudge NOI 2.6 7113:Charm Bracelet | 洛谷 P2871
[题目链接] ybt 1294:Charm Bracelet OpenJudge NOI 2.6 7113:Charm Bracelet 洛谷 P2871 [USACO07DEC]Charm Brac ...
- Charm Bracelet(0-1)
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...
- Charm Bracelet
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fil ...
最新文章
- Linq TO SQL中映射属性的说明
- 微信分享JSSDK-invalid signature签名错误的解决方案
- bigqury 认证
- linux编译安装madam,linux 下 使用 mdadm 创建阵列
- Scala _06集合_数组(二)
- WPF DataGrid
- jq执行2次同样的方法怎么让第一次执行的不触发_你不知道的CMS GC
- leetcode题解179-最大数
- pandas.plotting
- android获取指针空间大小_Android进阶:Binder那么弱怎么面大厂?
- Windows 10专业版下如何启用语音识别功能
- ajax要不要入口函数,Ajax - SegmentFault 思否
- 纯新手DSP编程--5.21--DSP/BIOS使用
- 入门到 精通 JavaScript中的正则表达式RE、RegExp
- 用一根网线连接树莓派跟pc
- sim800a指令_sim900a和sim800a的区别是什么
- linux上传网页文件大小,Apache启用GZIP压缩网页传输方法
- VS2010能否取代VS6?微软能否再创辉煌!
- 最适合freshman的Java习题集(四)数组
- android桌面布局保存在哪里,android-DatePickerDialog保存屏幕上的布局旋转
热门文章
- dnf大区服务器位置,dnf河北一区是跨几
- Ubuntu18.04网络连接图标上显示问号
- .net framework MVC ,API, 支持OAS3
- 安装transformers库出现pyyaml卸不掉问题解决方法
- html在线聊天界面模板,一款带气泡对话框的HTML5聊天应用界面模板
- html发展时间轴纵向插件,jquery响应式垂直时间轴插件vertical-timeline
- 爱情七十六课,门当户对
- PHP延迟静态捆绑Late Static Bindings
- java-pdf合并三种方法实现以及简单效率对比
- Swing + MySQL实现汽车租赁系统4.0