HDU3466(01背包变种)
Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4219 Accepted Submission(s): 1740
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.
#include"cstdio"
#include"cstring"
#include"algorithm"
using namespace std;
const int MAXN=;
struct Node{
int P,Q,v;
}goods[];
int n,W;
int dp[];
int comp(Node a,Node b)
{
return a.Q-a.P < b.Q-b.P;
}
int main()
{
while(scanf("%d%d",&n,&W)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<n;i++)
{
scanf("%d%d%d",&goods[i].P,&goods[i].Q,&goods[i].v);
}
sort(goods,goods+n,comp);
for(int i=;i<n;i++)
{
for(int j=W;j>=goods[i].Q;j--) dp[j]=max(dp[j],dp[j-goods[i].P]+goods[i].v);
}
printf("%d\n",dp[W]);
} return ;
}
HDU3466(01背包变种)的更多相关文章
- 01背包变种 第k解问题 hdu 2639
先说说普通01包的状态问题吧 普通的01背包,在状态转移的过程中为了求出最优解,一定是遍历了所有的情况 然后再求的最优解.那么对于第k最优解问题,我们只需要再加一个维度,用来记录每一个状态k优解的状态 ...
- HDU 3466(01背包变种
http://acm.hdu.edu.cn/showproblem.php?pid=3466 http://www.cnblogs.com/andre0506/archive/2012/09/20/2 ...
- poj 1837 天平问题(01背包变种)
题意:给你n个挂钩,m个砝码,要求砝码都用上,问有多少中方案数 题解:对于这道题目的状态,我们定义一个变量j为平衡度,当j=0的时候,表明天平平衡.定义dp[i][j]表达的含义为使用前n个砝码的时候 ...
- HDU 5543 Pick The Sticks:01背包变种
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5543 题意: 给你N个金条和一张长度为L的桌子.每个金条长度为a[i],价值为w[i].金条只能在桌子 ...
- dp之01背包hdu3466(带限制的,当你所拥有的钱数大于某个限定值时才可以购买该物品)
题意:买东西,每个东西有三个特征值,p代表价格,q代表你手中钱必须不低于q才能买这个物品,v代表得到的价值. mark:又是变种01背包,每做一个变种的,就是一种提高.. 按照q - p以由大到小的顺 ...
- HDU--3466(0-1背包+贪心/后效性)
题意是: 给你一些钱 m ,然后在这个国家买东西, 共有 n 件物品,每件物品有 价格 P 价值 V 还有一个很特别的属性 Q, Q 指 你如过想买这件物品 你的手中至少有这钱Q . 虽 ...
- HDU--3466 Proud Merchants (01背包)
题目http://acm.hdu.edu.cn/showproblem.php?pid=3466 分析:这个题目增加了变量q 因此就不能简单是使用01背包了. 网上看到一个证明: 因为如果一个物品是5 ...
- 洛谷P1926 小书童—刷题大军【01背包】
题目链接:https://www.luogu.org/problemnew/show/P1926 题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的 ...
- 01背包--hdu2639
hdu-2639 The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rooki ...
随机推荐
- C++静态库与动态库深入研究
什么是库 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常. 本质上来说库是一种可执行代码的二进制形式,可以被操 ...
- VueJS表达式支持:逻辑控制或运算
HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <titl ...
- bootstrap之鼠标操作
TouchLongClick package io.appium.android.bootstrap.handler; import android.os.SystemClock; import co ...
- libraries_v140_x64_py35_1.0.1.tar.bz2 libraries_v120_x64_py27_1.1.0.tar 下载链接以及百度云下载链接
下载链接 wget -c https://github.com/willyd/caffe-builder/releases/download/v1.0.1/libraries_v140_x64_p ...
- 对A-Star寻路算法的粗略研究
首先来看看完成后的效果: 其中灰色代表路障,绿色是起点和移动路径,红色代表终点 // = openArray[i+1].F) { minNode = openArray[i+1]; } } sta ...
- Apcahe Shiro学习笔记(一):简介及运行官方Demo
一.Apache Shrio: apache shiro 是一个功能强大和易于使用的Java安全框架,为开发人员提供一个直观而全面的的解决方案的认证,授权,加密,会话管理. 支持认证跨一个或多个数据源 ...
- javascript点滴积累
1. javascript中的array, set, map 均为数据容器,使用iterable内置的forEach方法 var a = ['A', 'B', 'C'];a.forEach(funct ...
- Spring LDAP
LDAP Spring LDAP 使用 - Sayi像秋天一样优雅 - 开源中国社区 http://docs.spring.io/spring-ldap/docs/current/reference/ ...
- PHP获取IP
<?php $iipp = $_SERVER["REMOTE_ADDR"]; echo $iipp ; ?>
- 误用了 react-scripts eject 命令
react 小白编程 由于使用 create-react-app 脚手架构建项目的时候,会给几个命令用 其中一个命令吸引了我的注意力 yarn eject,因为构建完成后特别提示说“你不会想要用到这 ...