题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3466

  n个商人,每个商人有一个物品,物品有价格p、价值v还有一个交易限制q。q的意义是假如你现在拥有的钱数小于q,那么是不允许交易的。

  由于拥有了q这个量,使得整个交易过程有了顺序,这显然破坏了dp的无后效性。我们可以考虑如何先确定这个顺序,让我们可以正常使用dp。

  贪心选取q小p大的,也就是q-p差值从小到大排序。这样可以大致确定一个选择顺序,不会证。

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef struct Node {
int w, q, v;
}Node;
const int maxn = ;
int n, m;
int dp[maxn];
Node t[maxn]; bool cmp(Node a, Node b) {
return a.q - a.w < b.q - b.w;
} int main() {
// freopen("in", "r", stdin);
while(~scanf("%d %d", &n, &m)) {
for(int i = ; i < n; i++) {
scanf("%d%d%d", &t[i].w, &t[i].q, &t[i].v);
}
memset(dp, , sizeof(dp));
sort(t, t+n, cmp);
for(int i = ; i < n; i++) {
for(int j = m; j >= t[i].q; j--) {
dp[j] = max(dp[j], dp[j-t[i].w]+t[i].v);
}
}
printf("%d\n", dp[m]);
}
return ;
}

[HDOJ3466]Proud Merchants(贪心+01背包)的更多相关文章

  1. HDU 3466 Proud Merchants(01背包)

    这道题目看出背包非常easy.主要是处理背包的时候须要依照q-p排序然后进行背包. 这样保证了尽量多的利用空间. Proud Merchants Time Limit: 2000/1000 MS (J ...

  2. Proud Merchants(01背包变形)hdu3466

    I - Proud Merchants Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. HDU--3466 Proud Merchants (01背包)

    题目http://acm.hdu.edu.cn/showproblem.php?pid=3466 分析:这个题目增加了变量q 因此就不能简单是使用01背包了. 网上看到一个证明: 因为如果一个物品是5 ...

  4. hdu3466 Proud Merchants(01背包)

    https://vjudge.net/problem/HDU-3466 一开始想到了是个排序后的背包,但是排序的策略一直没对. 两个物品1和2,当p1+q2>p2+q1 => q1-p1& ...

  5. HDU 3466 Proud Merchants(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=3466 题意: 最近,iSea去了一个古老的国家.在这么长的时间里,它是世界上最富有和最强大的王国.结果,这个国家 ...

  6. HDU 3466 Proud Merchants【贪心 + 01背包】

    Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerfu ...

  7. TopCoder SRM502 Div1 500 贪心 01背包

    原文链接https://www.cnblogs.com/zhouzhendong/p/SRM502-500.html SRM502 Div1 500 好题. 首先,如果已经确定了解决所有问题的优先级, ...

  8. Codeforces1203F2. Complete the Projects (hard version) (贪心+贪心+01背包)

    题目链接:传送门 思路: 对于对rating有提升的项目,肯定做越多越好,所以把$b_{i} >= 0$的项目按rating要求从小到大贪心地都做掉,得到最高的rating记为r. 对于剩余的$ ...

  9. HDU3466-Proud Merchants(01背包变形)

    需要排序的01背包. 这种题排序时只需要考虑两个怎么排,重载小于号就可以了. 需要注意的是,如果一个物品你想先放进背包里,那么你排序是要放到后面!01背包的放置顺序的倒着的! 看到别人的博客都只是比较 ...

  10. 2018.09.22 ZJOI2005午餐(贪心+01背包)

    描述 上午的训练结束了,THU ACM小组集体去吃午餐,他们一行N人来到了著名的十食堂.这里有两个打饭的窗口,每个窗口同一时刻只能给一个人打饭.由于每个人的口味(以及胃口)不同,所以他们要吃的菜各有不 ...

随机推荐

  1. HDU1013Digital Roots

    G - Digital Roots Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   ...

  2. IO端口和IO内存

    为什么会有IO端口和IO内存 这主要原因是因为处理器的架构不同,这里我们使用arm来代表典型的使用IO内存架构,intel 80x86代表典型的使用IO端口架构.简单来说arm把所有寄存器(包括外部设 ...

  3. 如何使用 Docker 部署一个基于 Play Framework 的 Scala Web 应用?

    本文作者 Jacek Laskowski 拥有近20年的应用程序开发经验,现 CodiLime 的软件开发团队 Leader,曾从 IBM 取得多种资格认证.在这篇博文中,Jacek 分享了 Wars ...

  4. virtualenv 环境下 Nginx + Flask + Gunicorn+ Supervisor 搭建 Python Web

    在这篇文章里,我们将搭建一个简单的 Web 应用,在虚拟环境中基于 Flask 框架,用 Gunicorn 做 wsgi 容器,用 Supervisor 管理进程,然后使用 Python 探针来监测应 ...

  5. (转)Eclipse平台技术概述

    转载:周金根 http://zhoujg.blog.51cto.com/1281471/516833    Eclipse:Eclipse平台技术概述 2010-10-19 13:35:00 标签:E ...

  6. 在线API文档

    http://www.ostools.net/apidocs A Ace akka2.0.2 Android Ant Apache CXF Apache HTTP服务器 ASM字节码操作 AutoCo ...

  7. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  8. Xamarin for Visual Studio 3.11.666 Beta版 破解补丁

    注意:本版本是 Beta 版   现已推送到稳定频道 前提概要 全新安装请参考 安装 Xamarin for Visual Studio. 最新稳定版请参考 Xamarin for Visual St ...

  9. hdu 4027 Can you answer these queries? 线段树

    线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...

  10. Hortworks Hadoop生态圈简介

    Hortworks 作为Apache Hadoop2.0社区的开拓者,构建了一套自己的Hadoop生态圈,包括存储数据的HDFS,资源管理框架YARN,计算模型MAPREDUCE.TEZ等,服务于数据 ...