Proud Merchants

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

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
 
Author
iSea @ WHU
 
Source
 
题意: 购买物品,pi qi vi  (pi代表要花的钱,qi代表你当前的钱要大于等于这个值才能买,vi 价值了。)
      和单纯的01背包比较,多了qi,在这里就发生区别了。
          for(j=sum_money;j>=f[i].qi&&(j-f[i].vi)>=0;j--)
    采取的方式是 对 qi-pi进行从小到大排序,使得差值 越小的越先放。
         
    为什么要这样排序呢?动手画一下。详细的证明,以后再写。
         
          其实单纯的01背包它的差值就是0,所以还是有共性的。
 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std; struct node
{
int pi,qi,vi;
}f[];
int dp[]; bool cmp(node n1,node n2)
{
return (n1.qi-n1.pi)<(n2.qi-n2.pi);
} int main()
{
int n,sum_money,max;
int i,j,tmp;
while(scanf("%d%d",&n,&sum_money)>)
{
for(i=;i<=n;i++)
{
scanf("%d%d%d",&f[i].pi,&f[i].qi,&f[i].vi);
}
sort(f+,f++n,cmp);
memset(dp,,sizeof(dp)); for(i=;i<=n;i++)
{
for(j=sum_money;j>=f[i].qi&&(j-f[i].pi)>=;j--)
{
tmp=dp[j-f[i].pi]+f[i].vi;
if(tmp>dp[j])
dp[j]=tmp;
}
}
printf("%d\n",dp[sum_money]);
}
return ;
}
 
 
 
 
 

hdu 3466 Proud Merchants 01背包变形的更多相关文章

  1. HDU 3466 Proud Merchants(01背包)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  2. HDU 3466 Proud Merchants(01背包问题)

    题目链接: 传送门 Proud Merchants Time Limit: 1000MS     Memory Limit: 65536K Description Recently, iSea wen ...

  3. HDU 3466 Proud Merchants 排序 背包

    题意:物品有三个属性,价格p,解锁钱数下线q(手中余额>=q才有机会购买该商品),价值v.钱数为m,问购买到物品价值和最大. 思路:首先是个01背包问题,但购买物品受限所以应先排序.考虑相邻两个 ...

  4. HDU 3466 Proud Merchants 带有限制的01背包问题

    HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...

  5. hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)

    题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...

  6. hdu 3466 Proud Merchants(有排序的01背包)

    Proud Merchants Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) ...

  7. HDU 3466 Proud Merchants【贪心 + 01背包】

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  8. HDU 3466 Proud Merchants(01背包)

    这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...

  9. Proud Merchants(01背包)

    Proud Merchants Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

随机推荐

  1. zTree API中刷新树没效果

    想刷新树,但是根据API来的refresh无效 ---------------------------------------------------------------------------- ...

  2. Linux下简易进度条的实现

    在生活中,进度条是很常见的,那么,进度条是如何实现的呢? 首先,进度条的动态是利用人眼视觉暂留效果的.实际上是如下过程: 先输出:[=                                  ...

  3. Java学习--多态

    1. 多态 多态:同一个对象(实物),在不同时刻体现出来的不同状态 多态的前提: A:要有继承关系 B:要有方法重写 C:要有父类引用指向子类对象 父类 f = new 子类() 多态中的成员访问特点 ...

  4. 北京DNS

    202.106.0.20 202.106.196.115 202.106.46.151

  5. json "key" 注意

    json 的key只能是字符串 必须使用 双引号

  6. FPGA基础学习(8) --内部结构之存储单元

    目录 1. 基本结构 2. BRAM与DRAM的比较 3. BRAM的特点 4. Block Memory的使用 4.1 配置为RAM或ROM 4.2. 配置为FIFO 参考文献: 上一篇中提到了SL ...

  7. springAOP实现方法运行时间统计

    aop的before和after,寻思分别在两个方法里获得当前时间,最后一减就可以了. 因此,今天就探讨了一下这个问题,和大家分享一下. 创建maven工程,引入spring的依赖包,配置好appli ...

  8. 主流服务器虚拟化技术简单使用——Xen(一)

    Tips:因为博客园网页布局的原因,部分图片显示不清晰,可以放大网页查看清晰图片. 如果系统使用物理机,需要在BIOS里面开启Intel VT-x(或AMD-V),如果是VMware workstat ...

  9. python学习,day2:利用列表做购物车实例

    一个购物车 # coding=utf-8 # Author: RyAn Bi import sys , os goods = [['iphone',5800],['mate20pro',5000],[ ...

  10. 基础篇:3.4)3d模型绘制的好坏会影响产品合格率(注意点)

    本章目的:为了量产品的产能与合格率,重视3d图纸. 1.前言 作者希望本文能引起重视,是那些刚入行业的菜鸟: 还有只用2d图纸,便能绘制出能量产合格品的前辈大牛工程师. 2.3d图纸不合格的现状及典型 ...