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. struts开发&lt;struts中的參数传递.三&gt;

    不说废话,直接上干货 1.通过set和get传递參数 添加username 和password两个属性并添加set和get方法 package fzl.user.struts.demo; import ...

  2. Oracle的动态SQL

    例1:传递表名,和Where条件删除数据 CREATE OR REPLACE PROCEDURE raise_emp_salary (column_value NUMBER, emp_column V ...

  3. OO模式-Singleton

    讨论一: 既然仅仅有一个类?为什么非要用一个模式来定义?难道就不能用程序猿之间的约定又或者使用伟大的设计模式来完毕? 1)先来说说全局变量的优点,当定义一个全局变量时,不论什么一个函数或者一行代码都能 ...

  4. 对象克隆技术Object.clone()

    Java中对象的创建 clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象. 所谓的复制对象,首先要分配一个和源对象同样大小的空间,在这个空间中创建一个新的对象. ...

  5. windows恶意软件删除工具(MRT.exe)检查计算机是否感染病毒使用图解

    Microsoft Windows恶意软件删除工具可以检查运行 Windows XP.Windows 2000 和 Windows Server 2003 的计算机是否受到特殊.流行的恶意软件(包括 ...

  6. beef 安装使用

    http://www.freebuf.com/articles/web/5511.html

  7. 【摘抄】C++程序员练级攻略

    摘抄自互联网文章 作为C++程序员,或者说程序员一定要提升自己: 专访李运华:程序员如何在技术上提升自己-CSDN.NET专访徐宜生:坚决不做代码搬运工!-CSDN.NET 上面两个文章我觉得都不错. ...

  8. 【Java并发编程四】关卡

    一.什么是关卡? 关卡类似于闭锁,它们都能阻塞一组线程,直到某些事件发生. 关卡和闭锁关键的不同在于,所有线程必须同时到达关卡点,才能继续处理.闭锁等待的是事件,关卡等待的是其他线程. 二.Cycli ...

  9. Android学习之SeekBar(控制wav音频的声音)

    使用SeekBar调节声音 SeekBar控件其实就是一个高级点的进度条,就像我们在听歌,看电影用的播放器上的进度条一样,是可以拖动的,可以改变进度的一个进度条控件! SeekBar常用属性: and ...

  10. CSS-禁用a标签

    <style> a.disabled { pointer-events: none; filter: alpha(opacity=50); /*IE滤镜,透明度50%*/ -moz-opa ...