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. 简易Samba服务器配置

    Samba的作用是在Linux和windows之间通过网络进行资源共享.下面是简单的一个文件共享例子: 1.安装samba.samba-client服务 yum install samba samba ...

  2. Spring中JdbcTemplate使用RowMapper

    package com.cxl.demo.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util. ...

  3. Django中ORM简介与单表数据操作

    一. ORM简介  概念:.ORM框架是用于实现面向对象编程语言种不同类型系统的数据之间的转换 构建模型的步骤:重点 (1).配置目标数据库信息,在seting.py中设置数据库信息 DATABASE ...

  4. springmvc源码解析(二)

    架构流程: 1.  用户发送请求至前端控制器DispatcherServlet, 2.  DispatcherServlet收到请求调用HandlerMapping处理器映射器.  处理器映射器根据请 ...

  5. 有了art-template,如有神助

    <div class="form-group col-lg-12"> <label class="control-label col-lg-3 text ...

  6. eclipse导入项目文件以及 import项目文件后有个红色感叹号

    eclipse导入项目文件 步骤:File —>Import—>General—>Existing Projects into Workspace 然后进去选择项目文件的具体路径即可 ...

  7. 谈谈JAVA实现节假日验证

    我们需要两个类,第一个类: 我们叫它验证类. 第二个类: 它是对法定节假日的抽象. 第一步开始: 当验证类被初始化的时候,会加载本年的所有法定节假日到一个list里: thisYearHolidays ...

  8. sort-桶排序

    void list_insert(list<int> &t,int num) { auto iter=t.begin(); for(;iter!=t.end();++iter) { ...

  9. 分散的配置文件VS集中的注册表

    假设有这样一个工程,是这样设计的: 1整个软件.服务被切分为 由若干独立的多道程序(多个进程/微服务): 2 这些多道程序只是“机制mechanism”,而“策略strategy”写在各自用到的配置文 ...

  10. arcgis 浅入

    首先声明,此文只是用于学习,非商业用途!!20181226谷子弟留   有朋友需要用arcgis来学习分析图块,实现图块的分类和数据分析和统计. 于是网上找了找资源. http://pan.baidu ...