HDU 3466 Proud Merchants(01背包)
这道题目看出背包非常easy。主要是处理背包的时候须要依照q-p排序然后进行背包。
这样保证了尽量多的利用空间。
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2674 Accepted Submission(s): 1109
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?
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.
2 10
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
5
11
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) ///#define mod 10007 const int maxn = 5010;
using namespace std; int dp[maxn]; struct node
{
int p, q, v;
}f[510]; bool cmp(node a, node b)
{
return a.q-a.p < b.q-b.p;
} int main()
{
int n, m;
while(~scanf("%d %d",&n, &m))
{
for(int i = 1; i <= n; i++) scanf("%d %d %d",&f[i].p, &f[i].q, &f[i].v);
for(int i = 0; i <= m; i++) dp[i] = 0;
sort(f+1, f+n+1, cmp);
for(int i = 1; i <= n; i++)
for(int j = m; j >= f[i].q; j--) dp[j] = max(dp[j] , dp[j-f[i].p] + f[i].v);
printf("%d\n",dp[m]);
}
} /*
3 10
3 6 10
3 8 4
2 10 7
*/
HDU 3466 Proud Merchants(01背包)的更多相关文章
- 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: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- HDU 3466 Proud Merchants(01背包问题)
题目链接: 传送门 Proud Merchants Time Limit: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- HDU 3466 Proud Merchants 排序 背包
题意:物品有三个属性,价格p,解锁钱数下线q(手中余额>=q才有机会购买该商品),价值v.钱数为m,问购买到物品价值和最大. 思路:首先是个01背包问题,但购买物品受限所以应先排序.考虑相邻两个 ...
- HDU 3466 Proud Merchants 带有限制的01背包问题
HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...
- HDU 3466 Proud Merchants【贪心 + 01背包】
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- 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背包,微变形)
题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...
- Proud Merchants(01背包)
Proud Merchants Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
随机推荐
- 解决Delphi自带UTF8解码缺陷(使用API)
因为Delphi自带的转换函数遇到其无法识别的字符串就返回空,下面函数可解决该问题. function DecodeUtf8Str(const S: UTF8String): WideString;v ...
- linux下主要是VirtualBox及GuestAdditions的安装
Linux版本的VirtualBox下载:http://www.virtualbox.org/wiki/Linux_Downloads.请下载对应的版本. RedHat.RHEL:rpm -i vh ...
- [置顶] 自娱自乐6之Linux gadget驱动5(自编gadget驱动,包涵与之通讯的主机usb驱动,已调试通过)
这个代码调试,你首先要保证你的udc驱动没用问题,这个有些矛盾,应为我本来要用gadget驱动来调试udc驱动,结果反过来了. 这是在zero基础改的,大概的改动 1. 去掉loop. 2. sink ...
- Linux学习笔记2:如何快速的学习使用一个命令
Linux 分层 内核 库: .so 共享对象,windows:dll 动态链接库 应用程序 Linux的基本原则: 1.由目的单一的小程序组成:组合小程序完成复杂任务: 2.一切皆文件: 3.尽量避 ...
- res://ieframe.dll/acr_error.htm 纯手动解决方法
res://ieframe.dll/acr_error.htm 引起这个原因的是,你IE浏览器的扩展组件的问题,因为不知道是具体哪个组件出了问题,所以要采用一刀切的方法来处理: 在开始/或开始键+R, ...
- linux学习之(五)-linux文解压、压缩、安装
查看一个文件的类型 命令: file 文件名 创建一个.tar类型的压缩包使用命令:tar -cvf [文件名].tar 目录 例:tar -cvf a.tar yasuo/ ...
- foj 2150 Fire Game(bfs暴力)
Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M ...
- javaScript 工作必知(十) call apply bind
call 每个func 都会继承call apply等方法. function print(mesage) { console.log(mesage); return mesage; } print ...
- C#中各种计时器
1.使用 Stopwatch 类 (System.Diagnostics.Stopwatch) Stopwatch 实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间.在典型的 S ...
- php汉字截取
/** * 截取HTML,并自动补全闭合 * @param $html * @param $length * @param $end */ function subHtml($html,$length ...