F - Proud Merchants
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?
InputThere are several test cases in the input.
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.
OutputFor each test case, output one integer, indicating maximum value iSea could get.
Sample Input
2 10
10 15 10
5 10 5
3 10
5 10 5
3 5 6
2 7 3
Sample Output
5
11
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
struct node
{
int v1;
int c;
int w;
}a[];
int dp[];
bool cmp(node a,node b)
{
return a.c-a.v1<b.c-b.v1;
}
int main()
{
int n,v;
while(~scanf("%d%d",&n,&v))
{ memset(dp,,sizeof dp);
for(int i=;i<n;i++)
{
scanf("%d%d%d",&a[i].v1,&a[i].c,&a[i].w); }
sort(a,a+n,cmp);
for(int i=;i<n;i++)
for(int j=v;j>=a[i].c;j--)
{
dp[j]=max(dp[j],dp[j-a[i].v1]+a[i].w);
}
printf("%d\n",dp[v]);
}
return ;
}
排序的地方注意一下。。。因为A 需要的时间 A。V1+B.c B的时间是B.V1+A.C;
F - Proud Merchants的更多相关文章
- HDU3466 Proud Merchants[背包DP 条件限制]
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 ...
- Proud Merchants(01背包变形)hdu3466
I - Proud Merchants Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- 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 ...
- Proud Merchants
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) To ...
- Proud Merchants(POJ 3466 01背包+排序)
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- Proud Merchants(01背包)
Proud Merchants Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) To ...
- HDU3466 Proud Merchants [背包]
题目传送门 Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
随机推荐
- HDU 5242 Game(贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=5242 题意: 给出一棵树,每个节点都有一个权值,每次可以获得从根结点(1)到叶子节点上的所有权值和,每个节点只能 ...
- java复制文件夹中的所有文件和文件夹到另一个文件夹中
1.复制文件夹 public static void copyDir(String oldPath, String newPath) throws IOException { File file = ...
- ashx图片上传接收
发送数据流方法 /// <summary> /// PostBinaryData /// </summary> /// <param name="url&quo ...
- Given d and e, factorize N to attack RSA
题目如下: RSA算法的使用一般要求每个不同的用户有一个独立的模数N.有天,Bob脑洞大开,认为似乎没有必要这样做.只需要一个模数N,然后给不同的用户分发不同的e和d就好了.可惜这种做法有严重的安全漏 ...
- 力扣(LeetCode)13. 罗马数字转整数
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...
- stop 用法
1. stop 文档 $(selector).stop(stopAll,goToEnd) stopAll 可选.规定是否停止被选元素的所有加入队列的动画.goToEnd 可选.规定是否允许完成当前的动 ...
- Python编码简要说明
●python2默认编码:ASCII编码 达到正确显示,程序需要编码转换: UTF-8 -- >decode解码 --> Unicode Unicode -- > encode编码 ...
- VNPY思维导图架构
VNPY是使用人数世界第三,国内第一的量化交易框架,封装的接口主要有ctp(期货),wind,xtp(股票)等.内部包含回测.实盘.模拟盘等模块.数据库默认为MongoDB的no-sql数据库,基于p ...
- 20165327 预备作业3 Linux安装及学习
20165327 预备作业3 Linux安装及学习 一.学习基于VirtualBox虚拟机安装Ubuntu图文教程,在自己笔记本上安装Linux操作系统,注意尽量选用最新版本的VirtualBox和U ...
- 详细讲解Linux下安装python3(Python3.5.4)
https://jingyan.baidu.com/article/6b97984dd6dbb01ca2b0bf0a.html