Proud Merchants

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

Total Submission(s): 3557 Accepted Submission(s): 1479

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

2010 ACM-ICPC Multi-University Training Contest(3)——Host by WHU

按照q-p的大小进行排序,再进行01背包,至于为什么这样排序,网上的题解没有看懂,在我看来,普通的01背包每次的状态转移都是基于前一个状态,所以只有尽量减少状态的损失才可以得到最优解,而状态损失量就q-p

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm> using namespace std; typedef long long LL; typedef pair<int,int>p; const int INF = 0x3f3f3f3f; struct node
{
int p;
int q;
int v;
int dis;
}Th[550]; int Dp[5010]; int n,m; bool cmp(node a,node b)
{
return a.dis<b.dis;
}
int main()
{
while(~scanf("%d %d",&n,&m))
{
for(int i=0;i<n;i++)
{
scanf("%d %d %d",&Th[i].p,&Th[i].q,&Th[i].v);
Th[i].dis=Th[i].q-Th[i].p;
} memset(Dp,0,sizeof(Dp)); sort(Th,Th+n,cmp); for(int i=0;i<n;i++)
{
for(int j=m;j>=Th[i].q;j--)
{
Dp[j]=max(Dp[j],Dp[j-Th[i].p]+Th[i].v);
}
}
printf("%d\n",Dp[m]);
}
return 0;
}

Proud Merchants的更多相关文章

  1. HDU3466 Proud Merchants[背包DP 条件限制]

    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. Proud Merchants(POJ 3466 01背包+排序)

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

  4. Proud Merchants(01背包)

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

  5. HDU 3466 Proud Merchants(01背包)

    这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...

  6. Proud Merchants(01背包变形)hdu3466

    I - Proud Merchants Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  7. hdu 3466 Proud Merchants 01背包变形

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

  8. HDU3466 Proud Merchants [背包]

    题目传送门 Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/O ...

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

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

随机推荐

  1. 如何用Java解析CSV文件

    首先看一下csv文件的规则: csv(Comma Separate Values)文件即逗号分隔符文件,它是一种文本文件,可以直接以文本打开,以逗号分隔.windows默认用excel打开.它的格式包 ...

  2. Lintcode: Remove Node in Binary Search Tree

    iven a root of Binary Search Tree with unique value for each node. Remove the node with given value. ...

  3. csuoj 1120: 病毒

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 1120: 病毒 Time Limit: 3 Sec  Memory Limit: 128 ...

  4. 数据库 CRUD

    1.删除表 drop  table +表名 2.修改表 alter  table+表名+ add(添加)+列名+ int(类型) alter  table+表名+ drop(删除)+column(列) ...

  5. sql where 1=1

    这段代码应该是由程序(例如Java)中生成的,where条件中 = 之后的条件是通过 if 块动态变化的.例如: String sql="select * from table_name w ...

  6. MVC4 下DropDownList使用方法

    与MVC3相比,差别很大: 表现形式一: public ActionResult Main() { List<SelectListItem> items = new List<Sel ...

  7. js 实现精确加减乘除

    //加法 function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1] ...

  8. 夺命雷公狗---DEDECMS----9dedecms单标签

    我们这一节课开始将dedecms的标签了,dedecms里面的标签分好多个的,我们先来看下他的标签长得啥样的先: 随便点击一个修改即可见到标签了: 这里面上面的大文本框里面有标签的用法下面有参数的说明 ...

  9. yii2的redis扩展使用

    yii2支持了redis扩展,不需要在本地下载php的扩展库就可以很好的使用 1.下载windows的redis安装包打开cmd,进入安装包目录,使用redis-server.exe redis.co ...

  10. 数据库性能优化:SQL索引

    SQL索引在数据库优化中占有一个非常大的比例, 一个好的索引的设计,可以让你的效率提高几十甚至几百倍,在这里将带你一步步揭开他的神秘面纱. 1.1 什么是索引? SQL索引有两种,聚集索引和非聚集索引 ...