Proud Merchants HDU
来源:互联网 发布:赵洪文国 知乎 编辑:程序博客网 时间:2024/06/04 17:51
点击打开链接
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?
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.
2 1010 15 105 10 53 105 10 53 5 62 7 3
5
#include <cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{ int p,q; int val; int dif;}s[510];int cmp(node a,node b){ return a.dif<b.dif;}int dp[5010];int main(){ int n,m; while(~scanf("%d %d",&n,&m)){ for(int i=0;i<n;i++){ scanf("%d %d %d",&s[i].p,&s[i].q,&s[i].val); s[i].dif=s[i].q-s[i].p; } sort(s,s+n,cmp); memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++){ for(int j=m;j>=s[i].q;j--){ dp[j]=max(dp[j],dp[j-s[i].p]+s[i].val); } } printf("%d\n",dp[m]); }}
阅读全文
0 0
- hdu 3466 Proud Merchants
- HDU 3466 Proud Merchants
- hdu 3466 Proud Merchants
- hdu 3466 Proud Merchants
- hdu 3466 Proud Merchants
- HDU-3466-Proud Merchants
- HDU 3466 Proud Merchants
- hdu 3466 Proud Merchants
- HDU 3466 Proud Merchants
- HDU 3466 Proud Merchants
- hdu 3466 Proud Merchants
- HDU 3466 Proud Merchants
- HDU 3466 Proud Merchants
- HDU - 3466 Proud Merchants
- hdu 3466 Proud Merchants
- hdu 3466 Proud Merchants
- hdu 3466 Proud Merchants
- HDU 3466 Proud Merchants
- javascript为数组去掉重复元素
- Numpy 使用教程 1
- java学习笔记2
- vue---报错Error:ENOENT:no such file or directory,chmod.....js-beautify@1.7.0\**\css-beautify.js
- 使用Public-Key登录Linux服务器
- Proud Merchants HDU
- HDU 6214 Smallest Minimum Cut(网络流 最小割最少边数)
- 求解01背包- 我所学习和认知的
- Numpy 使用教程 2
- Mac系统git的使用与配置
- day09
- Numpy 使用教程 3
- 儿歌点点 换歌不算题 旧版 历史版本
- java中的static