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的更多相关文章
随机推荐
- Git------创建本地库时绿色标志不显示
转载: http://blog.csdn.net/zixiao217/article/details/77018392 解决方法: 按Win+R键打开运行对话框,输入 regedit.exe ,准备修 ...
- Extjs表单验证小结
//放在onReady的function(){}中 Ext.QuickTips.init(); //为组件提供提示信息功能,form的主要提示信息就是客户端验证的错误信息. Ext.form.Fiel ...
- vim分屏
使用vim分屏的时候 ,可以在终端直接输入 vim -On 1.php 2.php 3.php 垂直分屏 三个文件 如果是在某个窗口里面想打开另外一个文件如何做呢? 按下esc,然后按下冒号 输入 回 ...
- 绑定方式开始服务&调用服务的方法
1.编写activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- Explaining Delegates in C# - Part 6 (Asynchronous Callback - Way 3)
By now, I have shown the following usages of delegates... Callback and Multicast delegatesEventsOne ...
- HttpClient(二)-- 模拟浏览器抓取网页
一.设置请求头消息 User-Agent模拟浏览器 1.当使用第一节的代码 来 访问推酷的时候,会返回给我们如下信息: 网页内容:<!DOCTYPE html> <html> ...
- [SublimeText] Sublime Text 2 在 Ubuntu 上安装指南
1. 下载Sublime Text 2 在官网下载对应系统位数的版本,从压缩包中提取出源代码,解压后文件夹中的"sublime_text"双击即可直接运行. 2. 建立快捷链接 将 ...
- Lua中的table构造式(table constructor)
最简单的构造式就是一个空构造式{},用于创建一个空table. 构造式还可以用于初始化数组.例如,以下语句:days = {"Sunday", "Monday" ...
- Android开发懒人库 -- ButterKnife (转载)
ButterKnife:8.1.0的使用 http://www.jianshu.com/p/0392199a682b http://www.cnblogs.com/flyme/p/4517560. ...
- 杨辉三角(Pascal Triangle)的几种C语言实现及其复杂度分析
说明 本文给出杨辉三角的几种C语言实现,并简要分析典型方法的复杂度. 本文假定读者具备二项式定理.排列组合.求和等方面的数学知识. 一 基本概念 杨辉三角,又称贾宪三角.帕斯卡三角,是二项式系数在三 ...