Proud Merchants(POJ 3466 01背包+排序)
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4257 Accepted Submission(s): 1757
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.
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int n,m;
struct node
{
int p,q,v;
}a[];
int dp[];
bool cmp(node a,node b)
{
return a.q-a.p<=b.q-b.p;
}
int main()
{
int i,j;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(dp,,sizeof(dp));
for(i=;i<n;i++)
scanf("%d%d%d",&a[i].p,&a[i].q,&a[i].v);
sort(a,a+n,cmp);
for(i=;i<n;i++)
{
for(j=m;j>=a[i].q;j--)
dp[j]=max(dp[j],dp[j-a[i].p]+a[i].v);
}
printf("%d\n",dp[m]);
}
}
Proud Merchants(POJ 3466 01背包+排序)的更多相关文章
- Proud Merchants HDU - 3466 01背包&&贪心
最近,我去了一个古老的国家.在很长一段时间里,它是世界上最富有.最强大的王国.结果,这个国家的人民仍然非常自豪,即使他们的国家不再那么富有.商人是最典型的,他们每个人只卖一件商品,价格是Pi,但是如果 ...
- HDU 3466 Proud Merchants【贪心 + 01背包】
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- 3466 ACM Proud Merchants 变形的01背包
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3466 题意:假设你有M元,已经Pi,Qi,Vi(i为角标,1<i<N),当M>Qi,时才 ...
- hdu 3466 Proud Merchants 【限制性01背包】+【贪心】
题目链接:https://vjudge.net/contest/103424#problem/J 转载于:https://www.bbsmax.com/A/RnJW16GRdq/ 题目大意: 有n个商 ...
- [HDOJ3466]Proud Merchants(贪心+01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466 n个商人,每个商人有一个物品,物品有价格p.价值v还有一个交易限制q.q的意义是假如你现在拥有的 ...
- Proud Merchants HDU - 3466 (思路题--有排序的01背包)
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...
- Proud Merchants---hdu3466(有01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466 与顺序有关的01背包. 如果一个物品p = 5,q = 7,一个物品p = 5,q = 9,如果 ...
- HDU 3466 01背包变形
给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表 ...
- Re0:DP学习之路 Proud Merchants HDU - 3466
解法 排序+01背包 这里的排序规则用q-p升序排列这里是一个感觉是一个贪心的策略,为什么这样做目前也无法有效的证明或者说出来 然后就是01背包加了一个体积必须大于什么值可以装那么加一个max(p,q ...
随机推荐
- python 加密模块安装
我们使用Python做加密算法如AES.MD5.SHA等时,需要用到PyCrypto模块 PyCrypto模块的安装方法 1.一般在官方网站下载: https://www.dlitz.net/soft ...
- 从ASM迁移到ARM(1):平台支持的迁移服务
Azure上的ARM模式为用户带来更好的管理,更多新的特性,更好的体验,因此目前正在使用经典模式(ASM)的用户,在了解和使用了ARM之后,也在考虑如何将原来基于ASM模式的虚拟机,存储,网络等IAA ...
- word2pdf
在网上现在能查到的,并且能通过php调用相关接口,将word转换成pdf文件的有openoffice,访问网址为http://www.openoffice.org/download/index.htm ...
- cf C. Tourist Problem
http://codeforces.com/contest/340/problem/C #include <cstdio> #include <cstring> #includ ...
- QDataStream类参考(串行化数据,可设置低位高位,以及版本号),还有一个例子
QDataStream类提供了二进制数据到QIODevice的串行化. #include 所 有成员函数的列表. 公有成员 QDataStream () QDataStream ( QIODevice ...
- 如何允许外网可以连接mysql数据库
1.首先检查mysql所在服务器的防火墙,如果限制了外网对3306端口的连接,那么放开限制Linux服务器中执行 iptables -L 可以查看当前的防火墙规则iptables -F 可以清 ...
- 【HDU1233】还是畅通工程(MST基础题)
无坑,裸题.直接敲就恩那个AC. #include <iostream> #include <cstring> #include <cstdio> #include ...
- Android学习笔记__1__Android体系架构
Android 体系结构图 Android作为一个移动设备的平台,其软件层次结构包括了一个操作系统(OS),中间件(MiddleWare)和应用程序(Application).根据Android的软件 ...
- Ajax 介绍
Ajax的关键技术: 异步处理数据 使用XHTML(HTML)和CSS构建标准化的展示层 使用DOM(document object model)进行动态显示和交互 使用XML和XSLT进行数据交换 ...
- Handsontable通用方法
1.clear():清空数据 2.createCol(index,amount,createAutomatically):添加列 index:列索引,amount:添加的列总数,crea ...