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. mongodb 关闭服务器

    ./mongo use admin db.shutdownServer() 啦啦啦

  2. cocos2dx 3.0 scrollview 在android下面背景變綠色了

    在windows上面跑的是OK的,  在android下面跑的時候就變成這樣子了:

  3. iOS 苹果标识符

  4. Linux od命令(以指定进制显示文件)

    从“读取二进制文件”出发,到od命令的使用 在桃村实习期间,一直努力做毕业设计,我的毕业设计中有一个内容就是读取SEGY文件.在读取文件时,经常遇到的问题时你要读取浮点型数据,这时你就必须考虑你所使用 ...

  5. Unique ID Generate Notes

    Unique ID generation in distributed systems http://www.slideshare.net/davegardnerisme/unique-id-gene ...

  6. 使用 vux 框架

    1)vux官网:https://vux.li/#/ 2)通过 vue-cli 工具使用 vux 1.如果没有安装 nodejs,请先前往 nodejs 官网下载并安装 nodejs,传送门:https ...

  7. CM和CDH的安装-进阶完成

    安装Cloudera Manager Server 和Agent 1.在cdh1解压cloudera-manager-el6-cm5.9.0_x86_64.tar.gz(cdh1节点)tar -zcv ...

  8. 【代码审计】iCMS_v7.0.7 keywords.admincp.php页面存在SQL注入漏洞分析

      0x00 环境准备 iCMS官网:https://www.icmsdev.com 网站源码版本:iCMS-v7.0.7 程序源码下载:https://www.icmsdev.com/downloa ...

  9. php-fpm 配置进程池

    什么是 php-fpm :php 是作为一个独立服务存在的,这个服务叫做 php-fpm什么是 php-fpm pool :也就是 php-fpm 的进程池,这个进程池中运行了多个子进程,用来并发处理 ...

  10. Memcached 运行状态

    memcached-tool 命令用于查看 Memcached 运行状态,用法如下: Usage: memcached-tool <host[:port] | /path/to/socket&g ...