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_houriN), an ending hour (starting_houri < ending_houriN), 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 ≤ RN) 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

这题想法非常简单就是先排序,再判断第i个要不要加进时间表里(1,时间上是否符合.2,利益最大化)
#include <iostream> //这题用到滚动数组,先对时间开始进行排序,dp[i]代表前i个时间段的效率
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[1100];
struct node
{
int start,ende,eff;
}exa[1100];
bool cmp(node x,node y)
{
if(x.start==y.start)
return x.ende<y.ende;
return x.start<y.start;
}
int main()
{
int n,m,r;
cin>>n>>m>>r;
memset(dp,0,sizeof(dp));
for(int i=0;i<m;i++)
{
cin>>exa[i].start>>exa[i].ende>>exa[i].eff;
}
sort(exa,exa+m,cmp);
for(int i=0;i<m;i++) dp[i]=exa[i].eff;
ll ans=0;
for(int i=0;i<m;i++)//判断第i个要不要加进去
{
for(int j=0;j<i;j++)
{
if(exa[j].ende+r<=exa[i].start) dp[i]=max(dp[i],dp[j]+exa[i].eff);
}
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
return 0;
}

  

D - Milking Time 动态规划的更多相关文章

  1. POJ - 3616 Milking Time (动态规划)

    Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...

  2. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

  3. 【POJ - 3616】Milking Time(动态规划)

    Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...

  4. 【动态规划】bzoj1642 [Usaco2007 Nov]Milking Time 挤奶时间

    区间按左端点排序,dp. #include<cstdio> #include<algorithm> using namespace std; #define N 1001 st ...

  5. 动态规划:POJ 3616 Milking Time

    #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...

  6. poj 3616 Milking Time

                                                                                                 Milking ...

  7. Milking Time

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  8. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

  9. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

随机推荐

  1. [深度学习] 最全优化方法总结比较--SGD,Adagrad,Adadelta,Adam,Adamax,Nadam

    SGD 此处的SGD指mini-batch gradient descent,关于batch gradient descent, stochastic gradient descent, 以及 min ...

  2. 深度学习之PyTorch实战(2)——神经网络模型搭建和参数优化

    上一篇博客先搭建了基础环境,并熟悉了基础知识,本节基于此,再进行深一步的学习. 接下来看看如何基于PyTorch深度学习框架用简单快捷的方式搭建出复杂的神经网络模型,同时让模型参数的优化方法趋于高效. ...

  3. [JLOI 2016]成绩比较

    Description 题库链接( \(\text{bzoj}\) 不知道为什么过不了啊... \(\text{luogu loj}\) 都能过...就给 \(\text{luogu}\) 的链接了. ...

  4. NLog基础配置

    <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nl ...

  5. LeetCode 键盘行-Python3.7<四>

    500. 键盘行 题目网址:https://leetcode-cn.com/problems/keyboard-row/hints/ 给定一个单词列表,只返回可以使用在键盘同一行的字母打印出来的单词. ...

  6. 【Java基础】15、负数的二进制表示方法

    在计算机中,负数以其正值的补码形式表达. 什么叫补码呢?这得从原码,反码说起. 原码:一个整数,按照绝对值大小转换成的二进制数,称为原码. 比如 00000000 00000000 00000000 ...

  7. python学习之老男孩python全栈第九期_day001作业

    1.使用while循环输入 1 2 3 4 5 6     8 9 10 count = 0 while count <= 9: count += 1 if count == 7:continu ...

  8. blfs(systemv版本)学习笔记-安装、配置和使用wpa_supplicant无线网络连接工具

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! wireless项目地址:http://www.linuxfromscratch.org/blfs/view/8.3/basic ...

  9. 【工具相关】Web-HTML特殊字符对照表

    特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 特殊符号 命名实体 十进制编码 Α Α Α Β Β Β Γ Γ Γ Δ Δ Δ Ε Ε Ε Ζ Ζ Ζ Η Η Η Θ Θ Θ Ι Ι ...

  10. 【代码笔记】iOS-tableView滑动的范围函数

    //tableview滑动的范围 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { myTableView.contentSize = C ...