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

* 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

套用0-1背包的模版即可,这是我写的最快的一次,用了20分钟,并且一次就过了.

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相关推荐

  1. 【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 ...

  2. POJ 3624 Charm Bracelet

    DP 一直是心中痛,不多说了,这个暑假就坑在这上了. 这暑假第一道DP题,01背包问题. 题意是说物品有 重量和价值 ,但你能承受的重量有限,问你能带的最大价值. 这题数组开大点,尽管不知道有啥坑点, ...

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

  4. 洛谷——P2871 [USACO07DEC]手链Charm Bracelet

    https://www.luogu.org/problem/show?pid=2871 题目描述 Bessie has gone to the mall's jewelry store and spi ...

  5. Charm Bracelet(POJ-3624)

    Problem Description Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of cours ...

  6. 【Charm Bracelet】题目解析~~

    题目: [Charm Bracelet] 有n个物品,编号为i的物品的重量为w[i],价值为c[i],现在要从这些物品中选一些物品装到一个容量为m的背包中,使得背包内物体在总重量不超过m的前提下价值尽 ...

  7. 信息学奥赛一本通 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 ...

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

  9. Charm Bracelet

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

最新文章

  1. Linq TO SQL中映射属性的说明
  2. 微信分享JSSDK-invalid signature签名错误的解决方案
  3. bigqury 认证
  4. linux编译安装madam,linux 下 使用 mdadm 创建阵列
  5. Scala _06集合_数组(二)
  6. WPF DataGrid
  7. jq执行2次同样的方法怎么让第一次执行的不触发_你不知道的CMS GC
  8. leetcode题解179-最大数
  9. pandas.plotting
  10. android获取指针空间大小_Android进阶:Binder那么弱怎么面大厂?
  11. Windows 10专业版下如何启用语音识别功能
  12. ajax要不要入口函数,Ajax - SegmentFault 思否
  13. 纯新手DSP编程--5.21--DSP/BIOS使用
  14. 入门到 精通 JavaScript中的正则表达式RE、RegExp
  15. 用一根网线连接树莓派跟pc
  16. sim800a指令_sim900a和sim800a的区别是什么
  17. linux上传网页文件大小,Apache启用GZIP压缩网页传输方法
  18. VS2010能否取代VS6?微软能否再创辉煌!
  19. 最适合freshman的Java习题集(四)数组
  20. android桌面布局保存在哪里,android-DatePickerDialog保存屏幕上的布局旋转

热门文章

  1. dnf大区服务器位置,dnf河北一区是跨几
  2. Ubuntu18.04网络连接图标上显示问号
  3. .net framework MVC ,API, 支持OAS3
  4. 安装transformers库出现pyyaml卸不掉问题解决方法
  5. html在线聊天界面模板,一款带气泡对话框的HTML5聊天应用界面模板
  6. html发展时间轴纵向插件,jquery响应式垂直时间轴插件vertical-timeline
  7. 爱情七十六课,门当户对
  8. PHP延迟静态捆绑Late Static Bindings
  9. java-pdf合并三种方法实现以及简单效率对比
  10. Swing + MySQL实现汽车租赁系统4.0