Milking Time
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10841   Accepted: 4564

Description

Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0..N-1) so that she produces as much milk as possible.

Farmer John has a list of M (1 ≤ M ≤ 1,000) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour (0 ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency (1 ≤ efficiencyi ≤ 1,000,000) which indicates how many gallons of milk that he can get out of Bessie in that interval. Farmer John starts and stops milking at the beginning of the starting hour and ending hour, respectively. When being milked, Bessie must be milked through an entire interval.

Even Bessie has her limitations, though. After being milked during any interval, she must rest R (1 ≤ R ≤ N) hours before she can start milking again. Given Farmer Johns list of intervals, determine the maximum amount of milk that Bessie can produce in the N hours.

Input

* Line 1: Three space-separated integers: NM, and R
* Lines 2..M+1: Line i+1 describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi

Output

* Line 1: The maximum number of gallons of milk that Bessie can product in the N hours

Sample Input

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

Sample Output

43

Source

 
  • 普通dp
  • 按时间排序,把休息的时间加在每个时间段的末尾
  #include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e3 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; struct node{
int u, v, w;
LL s;
};
bool cmp(const node &l, const node &r){
return l.u<r.u;
}
node dp[maxn];
int n, m, r, a, b, c;
LL ans;
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d %d %d",&n,&m,&r)){
ans=;
for(int i=;i<=m;i++){
scanf("%d %d %d",&dp[i].u,&dp[i].v,&dp[i].w);
dp[i].v+=r;
dp[i].s=dp[i].w;
}
sort(dp+,dp++m,cmp);
for(int i=;i<=m;i++){
for(int j=;j<i;j++){
if(dp[j].v<=dp[i].u){
dp[i].s=max(dp[i].s,dp[j].s+dp[i].w);
}
}
ans=max(ans,dp[i].s);
}
printf("%d\n",ans);
}
return ;
}

POJ_3616_Milking Time的更多相关文章

随机推荐

  1. Java使用String类格式化当前日期

    在输出日期信息时,经常需要输出不同格式的日期格式,本实例中介绍了String字符串类中的日期格式化方法,实例使用不同的方式输出String类的日期格式参数值,组合这些值可以实现特殊格式的日期字符串. ...

  2. ios开发之--打印bool值

    eg:NSLog(@"Hello,objective-c!");   @表示应该当作NSString字符串来处理. NSLog相当于C语言中的printf,常用于文字输出 NSLo ...

  3. vmware下虚拟机不能上网问题解决

    这个问题困扰了好久,vmware下装的虚拟机可以通过DHCP获取单独IP,但当用到管控较严格的环境,需要它与主机共享IP时,就不好使了. 今天在一篇文章中找到答案,如下图,windows系统中要启动V ...

  4. MPAndroidChart market右边显示不全问题

    //lineChart.setMarkerView(new CustomChartMarkerView(activity, R.layout.line_chart_maker));//add mark ...

  5. css笔记 - animation学习笔记(二)

    animation动画 @keyframes规则 - 创建动画 from - to 等价于 0% - 100% 但是优先使用0% - 100%,因为浏览器兼容性还好点 animation 动画绑定 将 ...

  6. Android 性能分析工具 TraceView

    官方地址 http://developer.android.com/tools/debugging/debugging-tracing.html 推荐:http://blog.csdn.net/inn ...

  7. Word 2010 制作文档结构之图标自动编号设置

    注意: 使用图片自动编号时,如果文档标题使用的样式是通过“将所选内容保存为新快速样式”所生成的样式,则图片自动编号不会生效 因此设置标题样式时,不要 新建样式,直接使用word预设的“标题 1”样式和 ...

  8. Google APK下载

    在线下载google play中apk的网站 1.http://apps.evozi.com/apk-downloader 2.http://downloader-apk.com/ 3.http:// ...

  9. ORA-00600: internal error code, arguments: [kgl-no-mutex-held]

    一.环境 windows oracle 11.2.0.4 RAC 二.问题现象 1.连接数据库后,无法查询 2.报错信息:ORA-00600: internal error code, argumen ...

  10. NC 的高级应用

    高级用法: (1)作攻击程序用,例子: 格式1:type.exe c:\exploit.txt|nc -nvv 192.168.x.x 80 格式2:nc -nvv 192.168.x.x 80 &l ...