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. Matlab入门学习(矩阵、函数、绘图的基本使用)

    一.矩阵 1.定义和简单使用(一般的编程语言,数组下标都是从0开始的,但是MATLAB是从1开始的) >> a=[ ; ; ] a = >> b=[ ; ; ]; >&g ...

  2. myeclipse一些快捷键 错了或者没说到补充下

    Ctrl + 1 快速修复Ctrl + D  删除当前行 Ctrl + Alt + ↓ 复制当前行到下一行(复制增加)Ctrl + Alt + ↑ 复制当前行到上一行(复制增加)Alt + ↓ 当前行 ...

  3. 开始使用ASP.NET Core - 创建第一个Web应用

    .NET Core 是.NET Framework的新一代跨平台应用程序开发框架,是微软在一开始发展时就开源的软件平台,由于 .NET Core 的开发目标是跨平台的 .NET 平台,因此 .NET ...

  4. 理解ES6——Promise

    浏览器的控制台真是个好东西,啥都能干: 这就是Promise,能看出来啥? 1.是个构造函数,可以new实例. 2.自身有一些方法:all.race.reject.resolve... 3.原型上有c ...

  5. 理解AngularJS中的依赖注入

    点击查看AngularJS系列目录 理解AngularJS中的依赖注入 AngularJS中的依赖注入非常的有用,它同时也是我们能够轻松对组件进行测试的关键所在.在本文中我们将会解释AngularJS ...

  6. Maven在Windows中的配置以及IDE中的项目创建

    Maven在Windows下的配置 1.Maven下载地址:http://maven.apache.org/download.cgi,下载红框里的版本即可. 2.解压到D盘: 3.修改配置文件sett ...

  7. Problem 2144 Shooting Game fzu

    Problem 2144 Shooting Game Accept: 99    Submit: 465Time Limit: 1000 mSec    Memory Limit : 32768 KB ...

  8. poj1067威佐夫博奕

    取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31490   Accepted: 10374 Descripti ...

  9. Easy sssp

    Easy sssp 时间限制: 1 Sec  内存限制: 128 MB提交: 103  解决: 20[提交][状态][讨论版] 题目描述 输入数据给出一个有N(2  < =  N  < = ...

  10. 获取报告 Stream转string,利用字符串分割转换成DataTable

    protected void Button1_Click(object sender, EventArgs e) { MemoryStream stream = new MemoryStream(); ...