hdu 3466 Proud Merchants
这道题对q-p进行从小到大排序,举一个比较直观的例子:
4 20
5 15 20
8 12 19
2 16 21
9 11 13
按照q-p排序后每行dp的变化
0 0 0 0 0 0 0 0 0 0 0 13 13 13 13 13 13 13 13 13 13
0 0 0 0 0 0 0 0 0 0 0 13 19 19 19 19 19 19 19 32 32
0 0 0 0 0 0 0 0 0 0 0 13 19 19 19 20 33 39 39 39 39
0 0 0 0 0 0 0 0 0 0 0 13 19 19 19 20 40 41 54 60 60
没排序dp的变化
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 20 20 20 20 20
0 0 0 0 0 0 0 0 0 0 0 0 19 19 19 20 20 20 20 20 20
0 0 0 0 0 0 0 0 0 0 0 0 19 19 19 20 40 41 41 41 41
0 0 0 0 0 0 0 0 0 0 0 13 19 19 19 20 40 41 41 41 41
可以明显看出没有排序忽略了8 12 19
5 15 20 是从dp[10]开始更新
8 12 19是从dp[4]开始更新
2 16 21是从dp[12]开始更新
9 11 13是从dp[3]开始更新
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{int p,q,v;
}a[505];
int dp[5005];
bool cmp(node a,node b){return a.q-a.p<b.q-b.p;
}
int main(){int n,m,p,q,v;while(cin>>n>>m){for(int i=0;i<n;i++){scanf("%d%d%d",&a[i].p,&a[i].q,&a[i].v);}for(int i=0;i<=m;i++)dp[i]=0;sort(a,a+n,cmp);for(int i=0;i<n;i++){for(int j=m;j>=a[i].q;j--)dp[j]=max(dp[j-a[i].p]+a[i].v,dp[j]);}int ans=0;for(int i=0;i<=m;i++){if(dp[i]>ans)ans=dp[i];}cout<<ans<<endl;}
}
hdu 3466 Proud Merchants相关推荐
- 01背包入门:HDU 3466 Proud Merchants
这道题对我来说还是有点难度的,所以参考了两个博主的博客:博主1博主2 Problem Description Recently, iSea went to an ancient country. Fo ...
- 【HDU - 3466 】Proud Merchants(dp,背包问题,巧妙排序)
题干: Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and pow ...
- 【HDU 3466】【Proud Merchants】
题目: Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and pow ...
- HDU3466 Proud Merchants
题目描述: Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and p ...
- HDU - 3466(01背包理解)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466 题意:给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品价格P价值V还有一个很 ...
- HDU 3466 01背包变形
给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表 ...
- hdu 3466(dp)
讲解博客 针对单个物品好理解贪心策略,两个物品相对比的思路不易理解. #include<cstdio> #include<iostream> #include<cstri ...
- Proud Merchants
题目链接: https://vjudge.net/contest/348156#problem/I 题面: 翻译: 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有和最强大的王国.因此 ...
- D(背)P(包)专题
D(背)P(包)专题 标签(空格分隔): ACM DP 干货 ShengRang && Thea.R 2016.07.11 D背P包专题 01背包 POJ 2923 Reloc ...
- mvc ajax get请求,springMVC 中 ajax get 请求和 post 请求的坑以及参数传递
1, ajax 请求 无论为 post ,或者 get ,url中带有?形式的参数,后台都能以String类型变量接收,变量名称和参数名称必须一致 前台ajax: $.ajax( "prod ...
最新文章
- 显著性图matlab,cvpr14_saliency_code 2014上的关于图像显著性区域的检测matlab代码。 271万源代码下载- www.pudn.com...
- 如何在ArcMap中监听键盘鼠标事件
- Microservice Anti-patterns
- Chrome Android 60.X+ 不能自动播放audio音频的解决办法
- Windows环境配置Apache+Mysql+PHP
- java 开发平台idea_JAVA开发平台intellij idea使用教程:有哪些方法可以实现自动导入...
- javascript基础修炼——手把手教你造一个简易的require.js
- linux系统 远程桌面连接到服务器,Ubuntu 14.04服务器远程桌面连接
- Java的四种引用方式
- 51社区房间怎么用挂号器_冬季艾灸时,房间怎么排烟?
- linux中使用网易云音乐
- Appium:ios自动化环境搭建
- java 使用qq邮箱发送邮件报错 port: 465, response: 550 错误
- java订餐管理系统代码,基于JAVA的订餐管理系统
- 一分钟了解光纤、单模光纤、多模光纤
- The server time zone value ‘?й???????‘ is unrecognized or represents more than one time zone.
- 电脑上传,提高电脑上传速度 怎么提高文件上传速度
- 优秀笔记课件——WORD使用技巧
- 如何改变 Git 字体大小
- 时寒冰:中国房价下跌序幕刚刚拉开
热门文章
- 前++和后++引发的血案
- css中用#id.class的形式定义样式,为什么这样用,不直接写成.class.代码如下:#skin_0.selected{}这种的...
- bisect algorithm(python 的标准库函数 bisect model)
- 坑爹的libxml2 for mingw 编译
- [转]WCF RIA Services
- sqlserver shiwu
- SQL2000升级到2005过程中的用户和登录名问题
- 怎样理解和识别 Linux 中的文件类型
- spring security 参考 和 例子
- Ajax 六. JSON数据解析