HDU3466(01背包变种)
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4219 Accepted Submission(s): 1740
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?
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.
#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背包变种)的更多相关文章
- 01背包变种 第k解问题 hdu 2639
先说说普通01包的状态问题吧 普通的01背包,在状态转移的过程中为了求出最优解,一定是遍历了所有的情况 然后再求的最优解.那么对于第k最优解问题,我们只需要再加一个维度,用来记录每一个状态k优解的状态 ...
- HDU 3466(01背包变种
http://acm.hdu.edu.cn/showproblem.php?pid=3466 http://www.cnblogs.com/andre0506/archive/2012/09/20/2 ...
- poj 1837 天平问题(01背包变种)
题意:给你n个挂钩,m个砝码,要求砝码都用上,问有多少中方案数 题解:对于这道题目的状态,我们定义一个变量j为平衡度,当j=0的时候,表明天平平衡.定义dp[i][j]表达的含义为使用前n个砝码的时候 ...
- HDU 5543 Pick The Sticks:01背包变种
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意: 给你N个金条和一张长度为L的桌子.每个金条长度为a[i],价值为w[i].金条只能在桌子 ...
- dp之01背包hdu3466(带限制的,当你所拥有的钱数大于某个限定值时才可以购买该物品)
题意:买东西,每个东西有三个特征值,p代表价格,q代表你手中钱必须不低于q才能买这个物品,v代表得到的价值. mark:又是变种01背包,每做一个变种的,就是一种提高.. 按照q - p以由大到小的顺 ...
- HDU--3466(0-1背包+贪心/后效性)
题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有 价格 P 价值 V 还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...
- HDU--3466 Proud Merchants (01背包)
题目http://acm.hdu.edu.cn/showproblem.php?pid=3466 分析:这个题目增加了变量q 因此就不能简单是使用01背包了. 网上看到一个证明: 因为如果一个物品是5 ...
- 洛谷P1926 小书童—刷题大军【01背包】
题目链接:https://www.luogu.org/problemnew/show/P1926 题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的 ...
- 01背包--hdu2639
hdu-2639 The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rooki ...
随机推荐
- 百度地图 创建 自定义控件(vue)
1.组件代码 Bmap.vue <!-- 离线地图 组件 --> <template> <div id="map" :style="styl ...
- vue2.0 自定义 提示框(Toast)组件
1.自定义 提示框 组件 src / components / Toast / index.js /** * 自定义 提示框( Toast )组件 */ var Toast = {}; var sho ...
- 小贝_mysql select连接查询
select连接查询 简要: 一.union联合查询 二.左右内连接 一.union联合查询 作用: 把2次或多次查询结果合并起来 具体: (表1查询结果) union (表2查询结果) 运行: 先算 ...
- C语言函数的递归和调用
函数记住两点: (1)每个函数运行完才会返回调用它的函数:每个函数运行完才会返回调用它的函数,因此,你可以先看看这个函数不自我调用的条件,也就是fun()中if条件不成立的时候,对吧,不成立的时候就是 ...
- mini2440使用jlink烧写superboot到norflash
Jlink版本号:J-flash ARM V4.12 J-Flash ARM的配置. 一般说来file-->open project里面会找到一些*.jfl ...
- Linux问题,磁盘分区打不开了
Metadata kept in Windows cache, refused to mount. chkdsk /f http://www.bubuko.com/infodetail-1184937 ...
- Java Web工作原理(转载)
知识要点: 1.HTTP协议 2.web服务器的缺陷及其解决方案 3.对Servlet的认识 4.Servlet的主要任务 5.web容器对Servlet的支持包括的内容 HTTP协议---(Hype ...
- Tomcat Context 组件介绍(转载)
来源:http://diecui1202.iteye.com/blog/1037370 Context代表一个Web应用,它运行在某个指定的虚拟主机(Host)上:每个Web应用都是一个WAR文件,或 ...
- hbase shell删除没实用
用Xshell登陆linux主机后,在hbase shell下不能使用backspace和delete删除误输的指令,这是Xshell的配置问题: 在File->Properties->T ...
- Refusing to install package with name “XXXX”
我的执行步骤 我创建了一个名叫express的文件夹,想在这个工程中学习express 进入该文件夹,执行npm init来初始化package.json文件,一直回车. 我们会发现当前文件夹多了一个 ...