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 ...
随机推荐
- Java值创建线程的两种方式对比
在Java中创建线程的方式有两种,第一种是直接继承Thead类,另一种是实现Runable接口.那么这两种方式孰优孰劣呢? 采用继承Thead类实现多线程: 优势:编写简单,如果需要访问当前线程,只需 ...
- ERS卫星
http://www.esa.int/Our_Activities/Operations/ERS-2 ERS-2 ROLE Earth observation (EO) LAUNCH DATE 21 ...
- win8 VS2010 配制OpenGL
glut下载地址: http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip glut.h ---> C:\Progr ...
- Android开发:自定义GridView/ListView数据源
http://mobile.51cto.com/android-259861.htm 在开发中,我们常常会遇到比较复杂的GridView/ListView的布局,重新实现BaseAdapter不但能帮 ...
- opennebula auth module ldap
1,安装net-ldap addon ruby library for openldap
- Linux学习之六-Yum命令的使用
详细介绍一下yum命令的用法.如果你是一个Linux的初学者,一定会被软件的安装所困扰过,尽管RPM包解决了一定层度的问题,但有些RPM的包的依赖关系让人很是头疼.而YUM.APT等一些RPM包的管理 ...
- 郁闷的C小加(一)(后缀表达式)
郁闷的C小加(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 我们熟悉的表达式如a+b.a+b*(c+d)等都属于中缀表达式.中缀表达式就是(对于双目运算符来说 ...
- 【玩转Ubuntu】02. Ubuntu上搭建Android开发环境
一. 基本环境搭建 1.官网http://developer.android.com/sdk/index.html ,下载adt-bundle-linux-x86_64-20130729.zip 2. ...
- wikioi-1039-数的划分
将整数n分成k份,且每份不能为空,任意两种划分方案不能相同(不考虑顺序). dp[i][j]:把数i分成k分的方案数 则:dp[i][j]=sum(dp[i-j][t])(t>=1&&a ...
- PHP语言基础06 MySql By ACReaper
上篇介绍了如用PHP连接上MySql进行,并进行sql语句的执行.但是我们没有介绍,如何输出处理的结果,如何获得处理的结果. 这里要先说明Mysql有两种查询处理模式,一种是有缓冲的查询处理模式,一种 ...