HDU 3466 Proud Merchants(01背包)
这道题目看出背包非常easy。主要是处理背包的时候须要依照q-p排序然后进行背包。
这样保证了尽量多的利用空间。
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 2674 Accepted Submission(s): 1109
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.
2 10
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
5
11
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-10
///#define M 1000100
#define LL __int64
///#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x) ///#define mod 10007 const int maxn = 5010;
using namespace std; int dp[maxn]; struct node
{
int p, q, v;
}f[510]; bool cmp(node a, node b)
{
return a.q-a.p < b.q-b.p;
} int main()
{
int n, m;
while(~scanf("%d %d",&n, &m))
{
for(int i = 1; i <= n; i++) scanf("%d %d %d",&f[i].p, &f[i].q, &f[i].v);
for(int i = 0; i <= m; i++) dp[i] = 0;
sort(f+1, f+n+1, cmp);
for(int i = 1; i <= n; i++)
for(int j = m; j >= f[i].q; j--) dp[j] = max(dp[j] , dp[j-f[i].p] + f[i].v);
printf("%d\n",dp[m]);
}
} /*
3 10
3 6 10
3 8 4
2 10 7
*/
HDU 3466 Proud Merchants(01背包)的更多相关文章
- hdu 3466 Proud Merchants 01背包变形
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- HDU 3466 Proud Merchants(01背包)
题目链接: 传送门 Proud Merchants Time Limit: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- HDU 3466 Proud Merchants(01背包问题)
题目链接: 传送门 Proud Merchants Time Limit: 1000MS Memory Limit: 65536K Description Recently, iSea wen ...
- HDU 3466 Proud Merchants 排序 背包
题意:物品有三个属性,价格p,解锁钱数下线q(手中余额>=q才有机会购买该商品),价值v.钱数为m,问购买到物品价值和最大. 思路:首先是个01背包问题,但购买物品受限所以应先排序.考虑相邻两个 ...
- HDU 3466 Proud Merchants 带有限制的01背包问题
HDU 3466 Proud Merchants 带有限制的01背包问题 题意 最近,伊萨去了一个古老的国家.在这么长的时间里,它是世界上最富有.最强大的王国.因此,即使他们的国家不再那么富有,这个国 ...
- HDU 3466 Proud Merchants【贪心 + 01背包】
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- hdu 3466 Proud Merchants(有排序的01背包)
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- hdu 3466 Proud Merchants 自豪的商人(01背包,微变形)
题意: 要买一些东西,每件东西有价格和价值,但是买得到的前提是身上的钱要比该东西价格多出一定的量,否则不卖.给出身上的钱和所有东西的3个属性,求最大总价值. 思路: 1)WA思路:与01背包差不多,d ...
- Proud Merchants(01背包)
Proud Merchants Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
随机推荐
- CSS自学笔记(10):CSS3盒子模型
CSS3为CSS技术的升级版本.最新版本. 就CSS而言,它是一个模块,是一个庞大而又复杂的模块,但是在CSS3中,将这一个庞大的模块分解为一个个容易理解的同时又很精简的小模块,同时CSS3中又添加了 ...
- JSONObject和JSONArray
点击下载json工具 点击下载支持jar包 1.从Object到String 要先用Object对象构造一个JSONObject或者JSONArray对象,然后调用它的toString()方法即可 ( ...
- Linux查看网卡状态
观看网卡传送.接收数据包的状态 $ netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK ...
- 简洁的jsp
在开发 是使用tomcat7版本(7的jslt表达式语法检查更加严格) 1.去除生产html的不必要的空行 <%@ page trimDirectiveWhitespaces="tru ...
- [置顶] CSDN博客第三期云计算最佳博主评选
CSDN博客第二期云计算最佳博主排行圆满结束,恭喜所有上榜用户,为继续展示云计算方向的优秀博主,发掘潜力新星,为云计算方向的博客用户提供平台,CSDN博客第三期云计算最佳博主排行开始.同时,获奖者有机 ...
- 黑马程序员_static\访问权限\单例模式 大汇总
一.static关键字 1.用法 Static是一个修饰符,用于修饰成员,包括成员变量和成员函数.当成员被静态修饰后,就多了一种调用方式,除了可以被对象调用外,还可以直接被类名调用.System.ou ...
- unity3d银联支付出现闪退
在接入银联SDK的unity3d的游戏中,点击银联支付会出现游戏总是出现闪退现象 ,后来网上有资料说 打开银联的jar包,将里面的res/drawable目录下的文件,拷贝到您的工程的drawable ...
- asp-net-web-api 自定义URl插件
http://attributerouting.net/#asp-net-web-api https://github.com/johnpapa/CodeCamper/blob/master/Code ...
- D3学习教程
[ D3.js 入门系列 ] 入门总结 | OUR D3.JS http://www.ourd3js.com/wordpress/?p=396
- Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name
解决步骤: 1: Sql Server是否已经启动. 2: 检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433 3: ping 数据库 ...