这道题目看出背包非常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. 用gson 解 json

    1.json 简单介绍 轻量级数据存储传输文件,比xml精简. 2.Gson简单介绍 android中解json方式很多,比较常用json-lib  goole-Gson. json-lib要包含的包 ...

  2. Delphi窗体最大化按钮不可用情况下的最大化

    最大化按钮不可用,而且窗体最大化,我以前一直这样设置:在Object Inspector下把BorderIcons属性下的biMaximize属性设置为False,然后把WindowState属性设置 ...

  3. 翻书的效果:FMX.TSwipeTransitionEffect Animation

    This example shows how to use a TSwipeTransitionEffect transition and a TPathAnimation to simulate t ...

  4. 触发按钮改变panel面板上的小圆圈颜色

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TouChaCol implements ...

  5. break point

    结论: 当有break point时,$m_H(N)=O(N^{k-1})$ bounding function:当break point = k,时成长函数$m_H(N)$的上限这样可以忽略假设集的 ...

  6. poj 3250 Bad Hair Day(单调队列)

    题目链接:http://poj.org/problem?id=3250 思路分析:题目要求求每头牛看见的牛的数量之和,即求每头牛被看见的次数和:现在要求如何求出每头牛被看见的次数? 考虑到对于某头特定 ...

  7. Struts2 三、指定Struts2处理的请求后缀

    Action的请求通常情况下默认为以.action结尾,例如:http://localhost:9000/Struts2/hello/helloAction_sayHello.action    .a ...

  8. python 的一些高级编程技巧

    正文: 本文展示一些高级的Python设计结构和它们的使用方法.在日常工作中,你可以根据需要选择合适的数据结构,例如对快速查找性的要求.对数据一致性的要求或是对索引的要求等,同时也可以将各种数据结构合 ...

  9. 关于cocos2dx 3.0升级崩溃报错(unable to load native library) 和(Fatal signal 11 (SIGSEGV) at 0x00000000)

    近期一直在Windows平台开发cocos-2dx游戏,期间做了一次引擎升级,升级到了3.0正式版本号.Windows平台上表现非常正常,没有出现什么问题. 上周五准备公布一个安卓包,编译非常轻松的就 ...

  10. ActionBar隐藏修改图标和标题

    有时候在一些子页面或者内容页面,不需要显示ActionBar的标题栏图标.可用如下方式进行设置. 首先获取到ActionBar对象 ActionBar actionBar=getActionBar() ...