POJ 3616
来源:互联网 发布:李泽厚美的历程知乎 编辑:程序博客网 时间:2024/05/22 00:49
经典的挤牛奶。
一开始想法老是考虑在背包上,这类和背包还是有区别的。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;int n,m,r;int dp[1005];struct P{ int sta; int end; int pro;}p[1005];int cmp(const P & a,const P &b){ if(a.sta<b.sta) return 1; if(a.sta==b.sta && a.end<b.end) return 1; return 0;}int main(){ memset(dp,0,sizeof(dp)); cin >> n >> m >> r; for(int i=0;i<m;i++) { cin >> p[i].sta >> p[i].end >> p[i].pro; p[i].end+=r; } sort(p,p+m,cmp); for(int i=0;i<m;i++) { dp[i]=p[i].pro;//初始化dp每一个值为单次的值 for(int j=0;j<i;j++)//最多到当前项的前一项 { if(p[j].end<=p[i].sta)//如果能在当前项的时间前挤完牛奶 { dp[i]=max(dp[i],dp[j]+p[i].pro);//那么就更新成最大值 } } } int max1=0; for(int i=0;i<m;i++) { //cout << "***" << dp[i] << endl; max1=max(max1,dp[i]);//和背包的不同之处,最大值可能不是最后一次挤牛奶。 } cout << max1 << endl; return 0;}
阅读全文
0 0
- poj 3616
- poj 3616
- poj----3616
- poj 3616
- poj 3616
- POJ 3616
- POJ 3616
- poj 3616 Milking Time
- Poj 3616 (dp)
- POJ 3616 DP
- POJ 3616 Milking Time
- POJ-3616-Milking Time
- DP 之 poj 3616
- poj 3616 Milking Time
- POJ 3616 Milking Time
- poj 3616 Milking Time
- Milking Time.(POJ-3616)
- poj 3616 (DP)
- synchronized关键字与对象锁
- 解决myeclipse2015无法查看servlet等源码的问题
- postfix+mysql,dovecot+mysql
- Educational Codeforces Round 21总结
- WebRTC源码分析四:视频模块结构
- POJ 3616
- 将阿拉伯数字 翻译为 罗马数字
- Linux grep的应用
- IOS绘制圆形图片
- C#加密与解密数据
- 在末尾添加节点
- python cookbook学习笔记十三:Struct模块
- 使用Ajax实现JSP购物车功能原理
- javascript深拷贝代码实现