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. [UIKit学习]06.懒加载,模型,自定义代码段,重写构造方法

    懒加载 在get中加载,且只加载一次 - (NSArray *)shops { if (_shops == nil) { NSString *file = [[NSBundle mainBundle] ...

  2. OC——关于KVO

    我们知道在WPF.Silverlight中都有一种双向绑定机制,如果数据模型修改了之后会立即反映到UI视图上,类似的还有如今比较流行的基于MVVM设计模式的前端框架,例如Knockout.js.其实在 ...

  3. AFN默认请求和响应的处理

       1.默认的响应的解析      1.1 AFN默认不支持接受text/html数据类型,只需要增加即可     manager.responseSerializer.acceptableCont ...

  4. 【转载】关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案

    关于api-ms-win-crt-runtimel1-1-0.dll缺失的解决方案 目录 关于api-ms-win-crt-runtimel1-1-0dll缺失的解决方案 目录 安装VC redite ...

  5. 51nod 1270 数组的最大代价 思路:简单动态规划

    这题是看起来很复杂,但是换个思路就简单了的题目. 首先每个点要么取b[i],要么取1,因为取中间值毫无意义,不能增加最大代价S. 用一个二维数组做动态规划就很简单了. dp[i][0]表示第i个点取1 ...

  6. 无向图广度优先遍历及其matlab实现

    广度优先遍历(breadth-first traverse,bfts),称作广度优先搜索(breath first search)是连通图的一种遍历策略.之所以称作广度优先遍历是因为他的思想是从一个顶 ...

  7. XSS跨站脚步攻击及防范

    XSS(Cross Site Script)跨站脚本攻击.它指的是恶意攻击者往Web 页面里插入恶 意html 代码,当用户浏览该页之时,嵌入其中Web 里面的html 代码会被执行,从而达到侵害用户 ...

  8. Gate One——用web展示Terminal(安装)

    Gate One可以用web来展示Terminal,虽然存在一些小缺陷,基本功能都还可以的,有兴趣的可以折腾一下. 安装环境: 系统:RHEL 6.1 ,系统自带python 2.6.6 下载需要安装 ...

  9. Java Socket通信以及可能出现的问题解决

    Java中基于TCP协议实现网络通信的两个类:客户端的Socket和服务器端的ServerSocket. Socket通信模型如图所示: 不管Socket通信的功能有多复杂,任何socket通信过程的 ...

  10. Elasticsearch(GEO)空间检索查询

    Elasticsearch(GEO)空间检索查询python版本 1.Elasticsearch ES的强大就不用多说了,当你安装上插件,搭建好集群,你就拥有了一个搜索系统. 当然,ES的集群优化和查 ...