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. intellij idea exclude from compile后怎么加回来

    File->Settings-> Build,Execution,Deployment->Compiler-> Execludes

  2. 当数据库某张表数据发生变化时,更新c#程序中缓存的用法

    参考:http://www.webkaka.com/tutorial/asp.net/2012/111912/(SqlDependency和SqlCacheDependency缓存的用法及具体步骤) ...

  3. CentOS6.5 安装HAProxy 1.5.20

    [在CentOS下安装haproxy] sudo yum install haproxy 编辑配置文件 vim /etc/haproxy/haproxy.cfg #------------------ ...

  4. java中HashSet详解(转)

    HashSet 的实现 对于 HashSet 而言,它是基于 HashMap 实现的,HashSet 底层采用 HashMap 来保存所有元素,因此 HashSet 的实现比较简单,查看 HashSe ...

  5. PostgreSQL Performance Monitoring Tools

    PostgreSQL Performance Monitoring Tools https://github.com/CloudServer/postgresql-perf-tools This pa ...

  6. JavaScript----marquee滚动标签 图片无缝滚动 插入百度地图

    页面的自动滚动效果,可由javascript来实现, 但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制. 使用marquee ...

  7. ASP.NET的一般处理程序对数据的基本操作

    TableList.ashx: <%@ WebHandler Language="C#" Class="TableList" %> using Sy ...

  8. .NET: C#: System.Diagnostics

    1. Trace & Debug 理解这两者的区别,Trace有个Listners.Add()非常好用,这里网上有个在ListBox里输出Debug和Trace信息的 using System ...

  9. C++之路进阶——边表

    边表:利用边的关系来表示一个图. 用到数组: head//head[i]表示从i点出发的第一条边的编号; next[i]//与第i条边起点相同的下一条边的编号; a[i]//第i条边的终点; val[ ...

  10. 在 msbuild 生成时,每次都生成很多css,js,img 文件,如果不想每次编译都有这些需要这样配置

    在 msbuild 不想生成一大堆文件,可以在 Web 项目的csproj 文件里,注释掉这一串. <!--<Import Project="$(VSToolsPath)\Web ...