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. JVM_垃圾收集器

    最近刚好有时间,就简单的看了下JVM的几种垃圾回收器,它们都是计算机历史发展的产物,先简单的做一个整理,并没有哪一款垃圾收集器就一定是最优,还需要结合使用场景.参数配置等进行考量,根据系统情况搭配出尽 ...

  2. ObjectARX二次开发创建自己的静态库,如同objectARX库一样

    objectARX二次开发的时候,经常会用到一些重复使用的类,如果类已经足够的好,那么我们可以编译成静态库,加快开发和编译的速度,提高工作效率. 环境vs2010+objectARX2012wizar ...

  3. centos6.5 命令行配置无线上网

    1.驱动下载地址: RTL8188无线网卡驱动下载 链接:https://pan.baidu.com/s/1ms-EbQCDxa76jPhYUPmr9Q 密码:r2vu 2.安装步骤: [root@c ...

  4. css盒子模型基础,margin-top塌陷,元素溢出

    现在布局不用table,一般用盒子模型来布局,也就是通常说的div+css,一个页面就是多个盒子的拼接   一. 初识盒子模型   例子1,测试盒子各属性设置   <head> <s ...

  5. [转载] 第三篇:数据仓库系统的实现与使用(含OLAP重点讲解)

    阅读目录 前言 创建数据仓库 ETL:抽取.转换.加载 OLAP/BI工具 数据立方体(Data Cube) OLAP的架构模式 小结 回到顶部 前言 上一篇重点讲解了数据仓库建模,它是数据仓库开发中 ...

  6. Kettle导入数据到Hive 出现多余的几行全部是null值的情况

    Kylin构建Cube的时候老是报错,说是有空值,其实源数据中是不存在空值的.为什么建Cube的时候会有呢? 执行完毕后使用Hive查询发现多了好几行全部是null的行. 这在源数据中是不存在的.分析 ...

  7. [整理] Nginx Location 匹配规则

    目录 规则语法 location 分类 匹配顺序: 扩展 location / {}和 location =/ {}的区别 如何快速测试 规则语法 语法 匹配规则 空 普通匹配(遵循最大前缀匹配规则, ...

  8. 用Laya制作简单的动画

    (function () { var layaGameInit = window.layaGameInit || {}; var WebGL = Laya.WebGL; var Browser = L ...

  9. HTML基础信息笔记

    HTML 是什么 HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 标签(tag) HTML 标签是由尖括号包围的关键词,比如 <html> ...

  10. hive Getting Started

    Apache HiveThe Apache Hive™ data warehouse software facilitates reading, writing, and managing large ...