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. zookeeper环境搭建及使用

    本文只讲解搭建步骤,先不讲原理相关知识 一.zookeeper下载地址 本文使用版本为zookeeper-3.4.10.tar.gz 地址:http://mirrors.shuosc.org/apac ...

  2. 翻译:MariaDB字符集和排序规则

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

  3. 《Go in action》读后记录:Go的并发与并行

    本文的主要内容是: 了解goroutine,使用它来运行程序 了解Go是如何检测并修正竞争状态的(解决资源互斥访问的方式) 了解并使用通道chan来同步goroutine 一.使用goroutine来 ...

  4. JQuery&原生js ——实现剪刀石头布小游戏

    前言 jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库( 或JavaScript框架).jQuery设计的宗旨是“write L ...

  5. PHP常用数组(Array)函数整理

    整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数.数组的分段和填充.数组与栈.数组与列队.回调函数.排序.计算.其他的数组函数等. 一.数组操作的基本函数 数组的键名和值 array_va ...

  6. Perfect Pth Powers poj1730

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

  7. [bzoj1066] [SCOI2007] 蜥蜴 - 网络流

    在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一个 ...

  8. MySQL show status 参数详解

    状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...

  9. 执行manage.py syncdb提示Unknown command: 'syncdb'

    1. 实验环境 ubuntu14.4 + django1.9.7 2. 问题描述 在配置完数据库mysite/settings.py后,通常需要运行 python manage.py syncdb 为 ...

  10. Linux系统初始化过程及运行级别简介

    Linux开机过程: 1 开机自检(BIOS):初始化硬件,查找启动介质 2 MBR引导 3 GRUB引导菜单:GRUB程序安装在Bootloader 4 加载内核(kernel) 5 运行INIT进 ...