首页 > 其他分享 >HDU 3466 Pround Merchants

HDU 3466 Pround Merchants

时间:2022-10-25 17:04:59浏览次数:78  
标签:3466 HDU 10 int money Merchants iSea 物品 include


题目链接:​​传送门​​ 题面:


Proud Merchants

Problem Description

Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.
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?

Input

There 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.

Output

For 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

题目大意:

输入有多组数据。现在有个物品元钱,每个物品有三个参数,分别是价格,买这个物品至少拥有的钱数,价值。你要用元钱买到价值尽量高的物品。

这题就比较巧妙了
多了一个参数
其实正解很简单
根据从小到大排序就好了
那为什么是这样的呢?
假设如果一个物品是
一个物品是
对第一个进行背包的时候只有
再对第二个进行背包的时候
会借用前面的
但是现在这些值都是0
会导致结果出错
于是要想到只有后面要用的值前面都可以得到
那样才不会出错

如果先
则至少需要的容量
如果先
至少需要的容量
那么就是
变形之后就是
所以要针对每个属性的来进行排序

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
struct node {
int w, v, p;
friend bool operator < (const node a, const node b) {
return a.p - a.w < b.p - b.w;
}
} e[A];
int T, n, V, f[A];

int main() {
while (cin >> n >> V) {
memset(f, 0, sizeof f);
for (int i = 1; i <= n; i++) cin >> e[i].w >> e[i].p >> e[i].v;
sort (e + 1, e + n + 1);
for (int i = 1; i <= n; i++)
for (int j = V; j >= e[i].p; j--)
f[j] = max(f[j], f[j - e[i].w] + e[i].v);
cout << f[V] << endl;
}
}


标签:3466,HDU,10,int,money,Merchants,iSea,物品,include
From: https://blog.51cto.com/lyle/5794948

相关文章

  • HDU 1171 Big Event In HDU
    题目链接:​​传送门​​BigEventinHDUProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’t......
  • HDU 3535 AreYouBusy
    题目链接:​​传送门​​题面:AreYouBusyProblemDescriptionHappyNewTerm!Ashavingbecomeajunior,xiaoArecognizesthatthereisnotmuchtimeforhertoAC......
  • HDU 2844 Coins
    题目链接:​​传送门​​​题面:ProblemDescriptionWhuacmersusecoins.TheyhavecoinsofvalueA1,A2,A3…AnSilverlanddollar.OnedayHibixopenedpurseandfoun......
  • HDU 1203 I NEED A OFFER!
    题目链接:​​传送门​​题面:INEEDAOFFER!ProblemDescriptionSpeakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了......
  • HDU 1114 Piggy-Bank
    题目链接:​​传送门​​Piggy-BankProblemDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Them......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......
  • HDU 2602 Bone Collector
    题目链接:​​传送门​​​题面:ProblemDescriptionManyyearsago,inTeddy’shometowntherewasamanwhowascalled“BoneCollector”.Thismanliketocollec......
  • HDU2376 Average distance
    题目链接:传送门求树上任意两点间的路径和的平均值非常套路统计每条边被经过多少次就是两边的点数的乘积注意精度就好#include<cstdio>#include<cstring>#include<alg......
  • HDU 1394 Minimum Inversion Number
    题目链接:​​传送门​​求出原数组的逆序对算把一个数从对头拿到队尾的过程中产生的贡献诶我好像昨天做过这个题#include<iostream>#include<cstdio>#include<cstring......
  • HDU 4135 Co-prime
    题目链接:​​传送门​​多组数据问区间内与互质的数的个数区间问题显然要转化成两个区间相减的问题也就是的答案减去的答案这里反过来求不互质的数的个数筛法可以提示我......