这道题目看出背包非常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

Problem Description
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.

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
There are several test cases in the 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
For each test case, output one integer, indicating maximum value iSea could get.


 
Sample Input
2 10
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
 
Sample Output
5
11
 
Author
iSea @ WHU
 
Source
#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背包)的更多相关文章

  1. hdu 3466 Proud Merchants 01背包变形

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  2. HDU 3466 Proud Merchants(01背包)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  3. HDU 3466 Proud Merchants(01背包问题)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  4. HDU 3466 Proud Merchants 排序 背包

    题意:物品有三个属性,价格p,解锁钱数下线q(手中余额>=q才有机会购买该商品),价值v.钱数为m,问购买到物品价值和最大. 思路:首先是个01背包问题,但购买物品受限所以应先排序.考虑相邻两个 ...

  5. HDU 3466 Proud Merchants 带有限制的01背包问题

    HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...

  6. HDU 3466 Proud Merchants【贪心 + 01背包】

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  7. hdu 3466 Proud Merchants(有排序的01背包)

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  8. hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)

    题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...

  9. Proud Merchants(01背包)

    Proud Merchants Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

随机推荐

  1. ubuntu_安装aptana3

    下面记录下偶怎么安装aptana3(aptana2应该也适用). 安装java运行时,偷看这里 说明:实际上偶并没有执行这步,因为发现在安装aptana3之前 java的运行时已经安装过了. 貌似是安 ...

  2. Spring 3.x企业实用开发实战(1)

    有关Spring的介绍这里就不赘述了,主要是学习了陈雄华版的<Spring 3.x企业应用开发实战>并做了一点笔记,以助于后期的回顾和复习. 废话不多说,直接进入主题,以下所有代码基于&l ...

  3. mysql 插入前 锁表问题

    $dbh = DBI->connect("dbi:mysql:database=$db_name;host=$ip;port=3306",$user,$passwd,{ Ra ...

  4. 初识Java--线程同步(2)

    本文讲述Java中的线程同步和生产者消费者问题,其中主要涉及线程同步和wait().notify()方法的用法. wait和notify方法只能用在线程同步中,wait和notify是object的方 ...

  5. javascritp第十课:面向对象

    js中的函数就是对象,对象就是函数,当js中需要使用面向对象,使用js闭包模拟面向对象,当函数作为对象使用时,每个单词首字母都大写 var obj=new object();  //js中默认就是ob ...

  6. 详解VB.net编写DLL(动态链接库、应用程序扩展)文件

    首先,我们启动VS(Visual-Studio简称),我使用的是VS2008版本. 新建一个项目-选择内裤(额...不好意思)→类库 ,名称就默认吧. 编写类库没有窗体设计,因此我们不能使用工具箱中的 ...

  7. Temporary Post Used For Theme Detection (19f70e1d-5d8d-4c19-aef1-5b5a71ae0c47 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

    This is a temporary post that was not deleted. Please delete this manually. (90462755-633b-4a0e-abb7 ...

  8. XenDesktop 5 PowerShell SDK Primer – Part 2 – Creating Hypervisor Connections and Hosts

    One of the new changes that you will see in XenDesktop 5 is the configuration of hypervisor connecti ...

  9. spring与hibernate整合事务管理的理解

    在谈Spring事务管理之前我们想一下在我们不用Spring的时候,在Hibernate中我们是怎么进行数据操作的.在Hibernate中我们每次进行一个操作的的时候我们都是要先开启事务,然后进行数据 ...

  10. 安装Ubuntu小计

    因为想学Linux了,所以想装一个Linux版本尝尝鲜,听说Ubuntu桌面版很炫,所以也没有啥特定理由的选了这个版本(实际我装的时候用了Ubuntu Kylin). 具体安装过程可以参考如下的教程: ...