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?

InputThere 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.

OutputFor 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
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node
{
int v1;
int c;
int w;
}a[];
int dp[];
bool cmp(node a,node b)
{
return a.c-a.v1<b.c-b.v1;
}
int main()
{
int n,v;
while(~scanf("%d%d",&n,&v))
{ memset(dp,,sizeof dp);
for(int i=;i<n;i++)
{
scanf("%d%d%d",&a[i].v1,&a[i].c,&a[i].w); }
sort(a,a+n,cmp);
for(int i=;i<n;i++)
for(int j=v;j>=a[i].c;j--)
{
dp[j]=max(dp[j],dp[j-a[i].v1]+a[i].w);
}
printf("%d\n",dp[v]);
}
return ;
}

排序的地方注意一下。。。因为A 需要的时间 A。V1+B.c     B的时间是B.V1+A.C;

F - 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背包)

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

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

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

  4. hdu 3466 Proud Merchants 01背包变形

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

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

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

  6. Proud Merchants

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

  7. Proud Merchants(POJ 3466 01背包+排序)

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

  8. Proud Merchants(01背包)

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

  9. HDU3466 Proud Merchants [背包]

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

随机推荐

  1. 2019年前端面试题 | CSS篇 (更新于4月15日)

    虽说刷面试题有走捷径之嫌,但我发现,对于我这样没有工作经历的人来说,其实是拓展自己实战技能和加深知识理解的一个好机会. 分享出来,也希望大家不要背完了事,正经的去细细琢磨各种原由. 本篇是一个题目合集 ...

  2. React Native原生模块向JS传递数据的几种方式(Android)

    一般情况可以分为三种方式: 1. 通过回调函数Callbacks的方式 2. 通过Promises的异步的方式 3. 通过发送事件的事件监听的方式. 参考文档:传送门

  3. 前端分页插件bootstrapPaginator的使用

     引入bootstrap-paginator.js <table class="table table-striped table-bordered table-hover dataT ...

  4. 解决输入git branch 进入编辑状态,mac下出现END,无法返回

    core.pager指定 Git 运行诸如log.diff等所使用的分页器,你能设置成用more或者任何你喜欢的分页器(默认用的是less), 当然你也可以什么都不用,设置空字符串: git conf ...

  5. java+selenium的helloworld

    在学校上测试课程,接触到自动化管理工具,在加上助教工作需要改作业,所以想着学下selenium这一强大的web自动化工具. 1.lenium官网:http://www.seleniumhq.org/  ...

  6. SpringBoot获取全局配置文件的属性以及@ConfigurationProperties实现类型安全的配置

    在SpringBoot,可以定义一个全局配置文件,全局配置文件有两种形式: 1). application.properties 2).application.yml 二者的后缀名不同,编辑的格式也不 ...

  7. django生成迁移文件

    1.创建虚拟环境 在终端上输入创建python3的虚拟环境 mkvirtualenv -p python3 虚拟环境的名字 安装django和pymysql 2.创建项目创建工程的命令: django ...

  8. Http Requests for PHP

    一.Requests for PHP 官网:http://requests.ryanmccue.info官方介绍:Requests is a humble HTTP request library. ...

  9. tchart5

    https://blog.csdn.net/wuyuanjingni/article/details/8585810

  10. 提取出一个组装基因组的gap(N)和重复序列区域,保存为bed格式

    参见: Question: How to extract allnon-seqencedpositions from a genome (Fasta file)? test.fa >chr1 N ...