HDU3466Proud Merchants(贪心&背包)
http://acm.hdu.edu.cn/showproblem.php?pid=3466
题目大意是说n个物品每个物品的花费是p,但是如果你现在的钱少于q就买不了这个物品,每个物品的价值是v,求有钱M时的最大价值。
一看这个题,就觉得直接按p背包还是按q背包都不对,然后就没有然后了。。。
然后看了题解:是说按q-p贪心,其实是这样,每次取q-p最小的,那么每次留下的自然就是最多的金钱。
至于严格的证明。。。。。。。待研究
剩下的就是01背包了。。,。。
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
#define mem0(a) memset(a,0,sizeof(a)) typedef long long LL;
const double eps = 1e-;
const int MAXN = ;
const int MAXM = ; struct NODE
{
int p,q;
int val;
}item[MAXN];
int N, M, DP[MAXM]; int cmp(NODE a, NODE b)
{
return a.q-a.p < b.q-b.p;
} int main()
{
while(~scanf("%d %d", &N, &M))
{
mem0(DP);
for(int i=;i<N;i++)scanf("%d %d %d", &item[i].p, &item[i].q, &item[i].val);
sort(item, item+N, cmp);
for(int i=;i<N;i++)
{
for(int j=M;j>=item[i].q;j--)
{
DP[j] = max(DP[j], DP[j-item[i].p]+item[i].val);
}
}
printf("%d\n", DP[M]);
}
return ;
}
HDU3466Proud Merchants(贪心&背包)的更多相关文章
- 【bzoj4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+背包dp
题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的 ...
- HDU3466-Proud Merchants(01背包变形)
需要排序的01背包. 这种题排序时只需要考虑两个怎么排,重载小于号就可以了. 需要注意的是,如果一个物品你想先放进背包里,那么你排序是要放到后面!01背包的放置顺序的倒着的! 看到别人的博客都只是比较 ...
- Proud Merchants(01背包)
Proud Merchants Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- hdu 3466 Proud Merchants 01背包变形
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- Installing Apps Kattis - installingapps (贪心 + 背包)
Installing Apps Kattis - installingapps Sandra recently bought her first smart phone. One of her fri ...
- HDU 5303 Delicious Apples(贪心 + 背包 2015多校啊)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5303 Problem Description There are n apple trees plan ...
- bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4922 题解 记录每一个串的没有匹配的右括号 \()\) 的数量为 \(a_i\),为匹配的左括 ...
- AT4120-[ARC096D]Sweet Alchemy【贪心,背包】
正题 题目链接:https://www.luogu.com.cn/problem/AT4120 题目大意 给出\(n\)个物品和一个容量\(m\),第\(i\)个物品体积为\(c_i\).除了第一个物 ...
- HDU 4003 [树][贪心][背包]
/* 大连热身A题 不要低头,不要放弃,不要气馁,不要慌张 题意: 给一棵树,每条边上有权值.给一个起点,放置n个机器人,要求使得任意一个节点至少被一个机器人经过. 每个机器人经过某条边时的代价为这条 ...
随机推荐
- 51nod1122 机器人走方格 V4
矩阵快速幂求出每个点走n步后到某个点的方案数.然后暴力枚举即可 #include<cstdio> #include<cstring> #include<cctype> ...
- ASP.NET vs MVC vs WebForms
许多ASP.NET开发人员开始接触MVC认为MVC与ASP.NET完全没有关系,是一个全新的Web开发,事实上ASP.NET是创建WEB应用的框架而MVC是能够用更好的方法来组织并管理代码的一种更高级 ...
- (转)FirstResponder 释放问题
FirstResponder 释放问题 转自:http://www.cnblogs.com/smileEvday/archive/2012/03/18/2405190.html View的FirstR ...
- memcached增删改查
1)add语法:add key flag expire byteskey 键flag 标志expire 过期时间,可以是秒或一个具体的时间戳bytes 要存的东西的bytes长度 PS:只能添加内存里 ...
- aspose输出表格
利用aspose在word中输出表格 序号 姓名 性别 <<TableStart:T>><<Index>> <<Name>> ...
- Struts2的crud
struts2的crud引出的问题: 1.当Action里面有其他类的实例引用属性时,当要用请求参数为该对象的属性赋值时,如何将其压入栈顶. 2.当有的操作(list)不需要创建该属性的实例对象时,或 ...
- 【转】使用ngrok快速地将本地Web服务映射到外网
为什么要使用ngrok? 作为一个Web开发者,我们有时候会需要临时地将一个本地的Web网站部署到外网,以供它人体验评价或协助调试等等,通常我们会这么做: 找到一台运行于外网的Web服务器 服务器上有 ...
- CMake实践(3)
一,本期目标 [sun@localhost t3]$ cat README t3:静态库(.a)与动态库(.so)构建 任务:1,建立一个静态库和动态库,提供HelloFunc函数供其他程序编程 ...
- PHP QR CODE生成二维码
用法: <?php include "./phpqrcode/phpqrcode.php"; $value="http://www.xxx.com"; $ ...
- android命名规范
Android 开发规范 (陈杨) (一)注意事项 1. 编码方式统一用UTF-8. Android Studio默认已是UTF-8,只要不去改动它就可以了. 2. 缩进统一为4个空格,将Tab si ...