HDU--3466 Proud Merchants (01背包)
题目http://acm.hdu.edu.cn/showproblem.php?pid=3466
这是一个排序的背包的问题。类似于饭卡http://acm.hdu.edu.cn/showproblem.php?pid=2546
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Item{
int p,q,v;
bool operator<(const Item &e)const
{
return (q-p)<(e.q-e.p);
}
}items[502];
int main()
{
int N,M,dp[5050];
while (scanf("%d%d",&N,&M)!=EOF)
{
for(int i=1;i<=N;i++)
scanf("%d%d%d",&items[i].p,&items[i].q,&items[i].v);
sort(items+1,items+1+N);
memset(dp,0,sizeof(dp));
for(int i=1;i<=N;i++)
for(int j=M;j>=items[i].q;j--){
dp[j]=max(dp[j],dp[j-items[i].p]+items[i].v);
}
printf("%d\n",dp[M]);
}
return 0;
}
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背包)
这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...
- 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 ...
随机推荐
- 在Linux(centos)下,安装Apache和PHP环境
1001 ll /opt/lampp/modules/ 1002 history | grep httpd 1003 vim /etc/httpd/conf/httpd.conf 1004 v ...
- Erlang学习记录:语法和特性
特性 大下排序:number < atom < reference < fun < port < pid < tuple < list < bit st ...
- Pipe进程之间的通信
#_author:来童星#date:2019/12/11#Pipefrom multiprocessing import Process, Pipedef f(conn): conn.send([42 ...
- Redis中取出值,转成对象
import com.fasterxml.jackson.databind.ObjectMapper; //转成companyEntity CompanyEntity company = mapper ...
- nginx反向代理时有无”/”的辨析
nginx反向代理是日常使用nginx时最常用到的功能之一.在配置url的过程中,“/”的有无经常是影响我们配置成功的关键,也是困扰我们的问题所在.在此,结合实际例子,作简要辨析. 场景一:利用根目录 ...
- Helvetic Coding Contest 2018 online mirror (teams allowed, unrated)F3 - Lightsabers (hard)
题意:n个数字1-m,问取k个组成的set方案数 题解:假设某个数出现k次,那么生成函数为\(1+x+...+x^k\),那么假设第i个数出现ai次,结果就是\(\sum_{i=1}^m(1+x+.. ...
- System.Web.HttpSessionStateBase.cs
ylbtech-System.Web.HttpSessionStateBase.cs 1.程序集 System.Web, Version=4.0.0.0, Culture=neutral, Publi ...
- (37)C#Linq
https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/let-clause 一.定义 Linq(Lang ...
- iOS开发NSLayoutConstraint代码自动布局
1.NSLayoutConstraint简介 适配界面大多用Masonry工具,也是基于NSLayoutConstraint写的!通过使用两个类方法实现自动布局: + (NSArray<__ki ...
- https://www.cnblogs.com/chinabin1993/p/9848720.html
转载:https://www.cnblogs.com/chinabin1993/p/9848720.html 这段时间一直在用vue写项目,vuex在项目中也会依葫芦画瓢使用,但是总有一种朦朦胧胧的感 ...