(01背包 先排序)Proud Merchants (hdu 3466)
Description
The merchants were the most typical, each of them only sold exactly one item, the price was Pi, but they would refuse to make a trade with you if your money were less than Qi, and iSea evaluated every item a value Vi.
If he had M units of money, what’s the maximum value iSea could get?
Input
Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.
Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.
The input terminates by end of file marker.
Output
Sample Input
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
Sample Output
11
题意: 有 n 个物品,每个物品都有一定的价值和花费,而且买的时候自己的钱不能低于那个物品的指标,问最后可以买到的物品的最大价值是多少。
思路: 需要对物品按 q-p 的值从小到大排序,因为这样可以保证每次更新的状态值从小到大递增,前面更新过的状态不会影响后面更新的状态。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std; const int N = ;
const int INF = 0x3fffffff;
const long long MOD = ;
typedef long long LL;
#define met(a,b) (memset(a,b,sizeof(a))) struct node
{
int p, q, v;
bool friend operator < (node n1, node n2)
{
return (n1.q-n1.p)<(n2.q-n2.p);
}
}a[N]; int dp[N]; int main()
{
int n, m; while(scanf("%d%d", &n, &m)!=EOF)
{
int i, j; met(a, );
met(dp, ); for(i=; i<=n; i++)
scanf("%d%d%d", &a[i].p, &a[i].q, &a[i].v); sort(a, a+n); for(i=; i<=n; i++)
{
for(j=m; j>=a[i].q; j--)
{
dp[j] = max(dp[j], dp[j-a[i].p]+a[i].v);
}
} printf("%d\n", dp[m]);
}
return ;
}
(01背包 先排序)Proud Merchants (hdu 3466)的更多相关文章
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- Proud Merchants HDU - 3466 01背包&&贪心
最近,我去了一个古老的国家.在很长一段时间里,它是世界上最富有.最强大的王国.结果,这个国家的人民仍然非常自豪,即使他们的国家不再那么富有.商人是最典型的,他们每个人只卖一件商品,价格是Pi,但是如果 ...
- Re0:DP学习之路 Proud Merchants HDU - 3466
解法 排序+01背包 这里的排序规则用q-p升序排列这里是一个感觉是一个贪心的策略,为什么这样做目前也无法有效的证明或者说出来 然后就是01背包加了一个体积必须大于什么值可以装那么加一个max(p,q ...
- hdu 3466 Proud Merchants(有排序的01背包)
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- hdu 3466 Proud Merchants 01背包变形
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- HDU 3466 Proud Merchants【贪心 + 01背包】
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- Proud Merchants(POJ 3466 01背包+排序)
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- HDU 3466 Proud Merchants(01背包)
这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...
- hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)
题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...
随机推荐
- 转 C++函数返回值,你必须注意的问题
归根结底,C++所面临的问题要求它提供各种各样的机制以保证性能,也许,这辈子也见不到C++能安全有效的自己进行内存垃圾回收..... 老程序猿都会提醒菜鸟,注意函数的返回值,因为,很可能,你的函数返回 ...
- c10k C10M
高性能网络编程(二):上一个10年,著名的C10K并发连接问题 阅读(22369) | 评论(9)收藏10 淘帖1 赞4 JackJiang Lv.9 1 年前 | |只看大图 1. ...
- tar 解压某个指定的文件或者文件夹
1. 先查看压缩文档中有那些文件,如果都不清楚文件内容,然后就直接解压,这个是不可能的 使用#tar -tf 压缩包名称,可以查看压缩包内容 2.解压某个文件 tar -zxvf zabbix.tar ...
- LibreOJ #6007. 「网络流 24 题」方格取数 最小割 最大点权独立集 最大流
#6007. 「网络流 24 题」方格取数 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- [都是原创]Php simplexml 添加节点
Php simplexml 添加节点 原始代码如下 //================<? //创建xml对象$xml = new SimpleXMLElement('<Messages ...
- 适合新手小白的UI学习路线完整版
UI设计是很多年轻人活着想转行学习的人的新职业目标,越来越多的人看到UI设计良好的就业发展前景,纷纷投入到UI设计的大军中来,想学习UI设计,很多小白并不知道从何开始学起,用什么样的方法去学习,所以今 ...
- Intellij idea 系列教程之破解方法
Intellij idea 系列教程之破解方法 Intellij idea 系列教程目录(https://www.cnblogs.com/binarylei/p/10347600.html) 到这个地 ...
- 64位ubuntu 兼容32位
http://www.cnblogs.com/mliudong/p/4086797.html 首先要打开64位系统对32位的支持 第一步:确认64为架构的内核 dpkg --print-archite ...
- Syslog和Windows事件日志收集
Syslog和Windows事件日志收集 EventLog Analyzer从分布式Windows设备收集事件日志,或从分布式Linux和UNIX设备.交换机和路由器(Cisco)收集syslog.事 ...
- 别人的Linux私房菜(3)主机规划与磁盘分区
磁盘阵列:RAID.将数个硬盘整合成为在操作系统看来是一个硬盘. Linux对笔记本电脑的支持:https://www.linux-laptop.net/ 几乎所有硬件设备存放于/dev/目录. SC ...