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
题意:类似的01背包问题,一开始看着不难,就写了但是案例就是不通过,看了好几天,才发现先原来购买顺序也会影响结果的;
解题思路:很显然,你会先判断q大,p小的物品买不买,对吧,因为在你价值最大,你应该尽可能的判断q大,p小的物品; 所以对q-p进行从小到大的排序,然后在进行DP;
感悟:今晚心情很差,只能写题;
代码:


#include

#include

#include

#include

#define maxn 5050

using namespace std;

struct node

{

    int
p,q,v;

    bool
operator < (const node & other) const

    {

       
return this->q-this->p

    }

};

int main()

{

   
//freopen("in.txt", "r", stdin);

    int
n,m;

   
while(~scanf("%d%d",&n,&m))

    {

       
int dp[maxn]={0};

       
node nod[maxn];

       
for(int i=0;i

           
scanf("%d%d%d",&nod[i].p,&nod[i].q,&nod[i].v);

       
sort(nod,nod+n);

       
for(int i=0;i

           
for(int j=m;j>=nod[i].p;j--)

       
{

           
if(j>=nod[i].q)

               
dp[j]=max(dp[j],dp[j-nod[i].p]+nod[i].v);

       
}

       
printf("%d\n",dp[m]);

    }

    return
0;

}

Problem X的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. Flask-WTF 配置、验证及日志P4

    参数配置 参数 说明 WTF_CSRF_ENABLED 设置为False以禁用所有CSRF保护 WTF_CSRF_CHECK_DEFAULT 使用CSRF保护扩展时,这可以控制每个视图是否受到默认保护 ...

  2. JAVA 局部变量表

    1. 除了 long,double 占用两个slot 之外,其他类型均占用一个slot. 2.在内容相同的情况下, 实例方法(不加 static) 会比 类方法 (static)对占用一个局部变量位置 ...

  3. 简单说明CGI是什么

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...

  4. Cornfields poj2019 二维RMQ

    Cornfields Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit S ...

  5. Perfect Pth Powers poj1730

    Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16383   Accepted: 37 ...

  6. 统计学习方法——CART, Bagging, Random Forest, Boosting

    本文从统计学角度讲解了CART(Classification And Regression Tree), Bagging(bootstrap aggregation), Random Forest B ...

  7. pongo英雄会-幸运数题解

    显然我们只要知道1~x范围有多少幸运数(用f(x)表示),lucky(x,y)=f(y)-f(x-1). 解法1. 计算排列数 由于y<=1000000000这个规模,我们不能暴力验证每个数是否 ...

  8. SQL server学习(五)——T-SQL编程之存储过程

    周五了,祝大家周末愉快. 之前一直在写SQL server的分享,今天再来个T-SQL编程中的存储过程. 存储过程 存储过程(procedure)类似于C语言中的函数,用来执行管理任务或应用复杂的业务 ...

  9. 第五章 MySQL事务,视图,索引,备份和恢复

    第五章 MySQL事务,视图,索引,备份和恢复 一.事务 1.什么是事务 事务是一种机制,一个操作序列,它包含了一组数据库操作命令,并且把所有的命令作为一个整体一起向系统提交或撤销操作请求.要么都执行 ...

  10. spring中WebApplicationContextUtils类说明

    WebApplicationContextUtils是一个抽象类,其提供了一个很便利的方法来获取spring应用的上下文即WebApplicationContext. 其中的静态方法getWebApp ...