POJ_3616_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: N, M, 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的更多相关文章
随机推荐
- ios开发之--跳转到指定的TabBarViewController中的某一个VIewController
比较简单,也很实用,方法大同小异,仅做记录,方法的系统记录如下: [self dismissViewControllerAnimated:YES completion:^{ // 这是从一个模态出来的 ...
- Express框架中如何引用ejs模板引擎
1.如何在项目中安装ejs模板引擎 在NodeJS指南中利用利用以下命令建立网站的基本结构: express -t ejs microblog 运行这个命令后继续运行 cd microblog &am ...
- Explaining Delegates in C# - Part 4 (Asynchronous Callback - Way 1)
So far, I have discussed about Callback, Multicast delegates, Events using delegates, and yet anothe ...
- SaltStack salt 命令
salt 是服务端远程批量操作多台客户端需要使用到的命令,常见用法如下: salt '*' # 指定对所有客户端主机进行操作 salt 'minion01' # 指定对单台客户端主机进行操作 salt ...
- SaltStack 批量分发文件
这里演示如何将 salt-master 上的文件批量分发到多台 salt-minion,步骤如下: [root@localhost ~]$ cat /srv/salt/top.sls # 先定义入口配 ...
- Nginx 72万连接性能测试(一)
转自:http://my.oschina.net/chenzhuo/blog/150200?p=2#comments 根据系统内存64G估算单台tengine做反向代理最高支持72万连接.为了验证达到 ...
- 深入浅出MFC——MFC六大关键技术仿真(二)
1. 仿真MFC目的:以MFC为例,学习application framework的内部运行.MFC六大关键技术: (1)MFC程序的初始化过程 (2)RTTI(Runtime Type Inform ...
- Foxmail邮箱最新应用指南 --如何使用「邮件标签」?
Foxmail邮箱最新应用指南--如何使用「邮件标签」? 最近看到很多的朋友收发电子邮件,现在我们帮助讲解下foxmail的标签功能,可以帮助我们整理我们的邮箱,让重要信息浮出水面. 1.鼠标右键邮件 ...
- 二、K3 WISE 开发插件《 工业单据老单客户端插件事件、属性、方法》
===================== 目录: 1.插件事件说明如下 2.插件属性说明如下 3.插件方法说明如下 ===================== 1.插件事件说明如下: 序号 事 ...
- 原生js--事件类型
1.表单事件: submit事件 reset事件 click事件 change事件 focus事件(不冒泡) (IE和ES5支持冒泡的focusin) blur事件(不冒泡) (IE和ES5支持冒泡的 ...