Proud Merchants

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4219    Accepted Submission(s): 1740

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
题意:有n个商品,买第i个需要Pi元,但手中的钱必须大于Qi元 ,所获得的价值为Vi,问给出M元,获得的最大价值为多少?
思路: 每个商品按q-p排序才会得到正确结果
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int MAXN=;
struct Node{
int P,Q,v;
}goods[];
int n,W;
int dp[];
int comp(Node a,Node b)
{
return a.Q-a.P < b.Q-b.P;
}
int main()
{
while(scanf("%d%d",&n,&W)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
{
scanf("%d%d%d",&goods[i].P,&goods[i].Q,&goods[i].v);
}
sort(goods,goods+n,comp);
for(int i=;i<n;i++)
{
for(int j=W;j>=goods[i].Q;j--) dp[j]=max(dp[j],dp[j-goods[i].P]+goods[i].v);
}
printf("%d\n",dp[W]);
} return ;
}
 

HDU3466(01背包变种)的更多相关文章

  1. 01背包变种 第k解问题 hdu 2639

    先说说普通01包的状态问题吧 普通的01背包,在状态转移的过程中为了求出最优解,一定是遍历了所有的情况 然后再求的最优解.那么对于第k最优解问题,我们只需要再加一个维度,用来记录每一个状态k优解的状态 ...

  2. HDU 3466(01背包变种

    http://acm.hdu.edu.cn/showproblem.php?pid=3466 http://www.cnblogs.com/andre0506/archive/2012/09/20/2 ...

  3. poj 1837 天平问题(01背包变种)

    题意:给你n个挂钩,m个砝码,要求砝码都用上,问有多少中方案数 题解:对于这道题目的状态,我们定义一个变量j为平衡度,当j=0的时候,表明天平平衡.定义dp[i][j]表达的含义为使用前n个砝码的时候 ...

  4. HDU 5543 Pick The Sticks:01背包变种

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意: 给你N个金条和一张长度为L的桌子.每个金条长度为a[i],价值为w[i].金条只能在桌子 ...

  5. dp之01背包hdu3466(带限制的,当你所拥有的钱数大于某个限定值时才可以购买该物品)

    题意:买东西,每个东西有三个特征值,p代表价格,q代表你手中钱必须不低于q才能买这个物品,v代表得到的价值. mark:又是变种01背包,每做一个变种的,就是一种提高.. 按照q - p以由大到小的顺 ...

  6. HDU--3466(0-1背包+贪心/后效性)

    题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有  价格 P    价值 V    还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...

  7. HDU--3466 Proud Merchants (01背包)

    题目http://acm.hdu.edu.cn/showproblem.php?pid=3466 分析:这个题目增加了变量q 因此就不能简单是使用01背包了. 网上看到一个证明: 因为如果一个物品是5 ...

  8. 洛谷P1926 小书童—刷题大军【01背包】

    题目链接:https://www.luogu.org/problemnew/show/P1926 题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的 ...

  9. 01背包--hdu2639

    hdu-2639 The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rooki ...

随机推荐

  1. 安装惠普M1136打印机一直处于“新设备已连接”状态怎么办?

    百度的答案是从控制面板的添加打印机入手,我试了遇到找不到设备的问题. 其实问题的原因是在安装驱动时一直把打印机到电脑的USB插着.我的解决方案是: 1.点击M1130MFP_M1210MFP开始安装, ...

  2. 百科知识 DCR文件如何打开

    使用IE可以打开,但是需要先安装Adobe Shockwave Player 天空软件下载地址:http://fpdownload.macromedia.com/get/shockwave/defau ...

  3. WPF简单计算器

  4. tree related problems (update continuously)

    leetcode Binary Tree Level Order Traversal 这道题是要进行二叉树的层次遍历.对于层次遍历,最简单直观的办法就是进行BFS.于是我们仅仅须要维护一个队列就能够了 ...

  5. Ubuntu 15.10

    安装Ubuntu 15.10后要做的事 http://blog.csdn.net/skykingf/article/details/45267517 ubuntu15.10 install-mac-t ...

  6. FFmpeg解码详细流程

    FFmpeg在解码一个视频的时候的函数调用流程.为了保证结构清晰,其中仅列出了最关键的函数,剔除了其它不是特别重要的函数. 下面解释一下图中关键标记的含义. 函数背景色 函数在图中以方框的形式表现出来 ...

  7. 让EasyDarwin只支持RTP over TCP传输

    我们经常需要EasyDarwin服务器支持公网流媒体传输,但很多时候,播放器默认都是通过RTP over UDP的形式在RTSP SETUP中请求,往往都以在内网接收不到UDP数据失败结束,那么我们如 ...

  8. 清理yum 缓存

    两条命令 yum clean all 以及 rm -rf /var/cache/yum/* 如何有效的清理yum缓存 - CSDN博客 https://blog.csdn.net/nsrainbow/ ...

  9. Performance Tuning Using Linux Process Management Commands

    [root@bigdata-server-02 /]# ps --help all Usage: ps [options] Basic options: -A, -e all processes -a ...

  10. 关于4Ps 、4Cs 、4Rs 、4Vs营销策略的内容及优劣比较