暑假集训第四周 DP C - Proud Merchants
来源:互联网 发布:分水岭算法示意图 编辑:程序博客网 时间:2024/06/07 03:04
C - Proud Merchants
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uDescription
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?
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.
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 1010 15 105 10 53 105 10 53 5 62 7 3
Sample Output
511
就加了一个排序而已
1234567891011121314151617181920212223242526272829
#include<stdio.h>#include<algorithm>#include<string.h>using namespace std;struct bone{ int a,b,c;} v[501];int cmp( bone x,bone y){ return x.b-x.a<y.b-y.a;}int main(){ int t,n,m,s,i,j,k,f[5010]; while(scanf("%d %d",&t,&n)!=EOF) { memset(f,0,sizeof(f)); for(i=0; i<t; i++) scanf("%d %d %d",&v[i].a,&v[i].b,&v[i].c); sort(v,v+t,cmp); for(i=0;i<t;i++) for(j=n;j>=v[i].b;j--) if(f[j]<f[j-v[i].a]+v[i].c) f[j]=f[j-v[i].a]+v[i].c; printf("%d\n",f[n]); } return 0;}
0 0
- 暑假集训第四周 DP C - Proud Merchants
- 暑假集训第四周阶段一 DP A - Robberies
- Proud Merchants(DP变形)
- 暑假集训第四周第一练
- 暑假集训第四周 阶段一 DP 动态规划 B - Bone Collector
- 暑假集训第四周 DP D - Big Event in HDU 分院
- 暑假集训第四周阶段二DP A - 最长公共子序列
- hdoj 3466 Proud Merchants 【DP】【01背包】
- hdu 3466 Proud Merchants(DP)
- hdu3466 Proud Merchants 01背包 排序 dp
- hdu 3466 Proud Merchants(DP)
- hdu 3466 Proud Merchants (排序的dp)
- HDU 3466 Proud Merchants【01dp】
- hdu 3466 Proud Merchants(贪心+DP)
- HDU 3466 Proud Merchants 贪心+dp
- Proud Merchants
- Proud Merchants
- Proud Merchants
- 08-03 网络通信(UDP) URL XML解析器 JSON、DOM、SAX 枚举
- 9种排序算法总结
- Java学习--(五)Buliding a Java Program(使用eclipse)
- 鸟哥的私房菜学习笔记十三 关于正则表达式
- C语言声明的优先级规则
- 暑假集训第四周 DP C - Proud Merchants
- HD2041 超级楼梯【斐波那契数列】
- 机器人的运动范围
- js 重载问题
- new Handler().postDelayed() 延迟intent跳转
- 关于Android下,XML文件的生成和解析方式
- python菜鸟日记3
- __attribute__((constructor))
- 迭代器失效