D - Milking Time 动态规划
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 这题想法非常简单就是先排序,再判断第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 动态规划的更多相关文章
- POJ - 3616 Milking Time (动态规划)
Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that sh ...
- 动态规划 POJ3616 Milking Time
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...
- 【POJ - 3616】Milking Time(动态规划)
Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...
- 【动态规划】bzoj1642 [Usaco2007 Nov]Milking Time 挤奶时间
区间按左端点排序,dp. #include<cstdio> #include<algorithm> using namespace std; #define N 1001 st ...
- 动态规划:POJ 3616 Milking Time
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- poj 3616 Milking Time
Milking ...
- Milking Time
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...
- POJ 3616 Milking Time(加掩饰的LIS)
传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
随机推荐
- MRTG在Windows平台的安装及使用
MRTG (Multi Router Traffic Grapher)是一款监控网络流量负载的免费软件,目前利用MRTG已经开发出了各式各样的统计系统: 1.系统资源负载统计,例如:磁盘空间.CPU负 ...
- Beego学习笔记
Beego学习笔记 Go 路由(Controller) 路由就是根据用户的请求找到需要执行的函数或者controller. Get /v1/shop/nike ShopController Get D ...
- 第4章 Selenium2-java WebDriver API (二)
4.8 定位一组元素 定位一组元素的方法与定位单个元素的方法类似,唯一的区别是在单词element后面多了一个s表示复数.定位一组元素一般用于以下场景: ·批量操作元素,例如勾选页面上所有的复选框. ...
- js实现全选/全不选、反选
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- rootkit(kbeast-v1)
Rootkit有应用级.内核级和硬件级 用的比较多的是内核级别,比如基于linux LKM编写的rootkit rootkit可以理解为一个超级管理员的工具箱,这个工具箱通过调用系统LKM接口可以动态 ...
- JavaScript之读取和写入cookie
首先先让我们简单地了解一下cookie. 在我们制作网页的过程中,经常需要把信息从一个页面传递给另一个页面,这时候就需要用到JavaScript中的cookie机制了.简单说来,cookie提 ...
- 作用域public、private、protected、以及不写时的区别?
区别如下: 作用域 当前类 同包 子孙类 其他 public √ √ √ √ protected √ √ √ X default √ √ X X private √ X X ...
- Mysql存储过程入门介绍
delimiter //一般情况下MYSQL以:结尾表示确认输入并执行语句,但在存储过程中:不是表示结束,因此可以用该命令将:号改为//表示确认输入并执行. 一.创建存储过程 1.基本语法: crea ...
- What are the differences between a pointer variable and a reference variable in C++?
Question: I know references are syntactic sugar, so code is easier to read and write. But what are t ...
- System.arraycopy 怎么使用的?
前言:看 ArrayList 的源码,发现 remove 方法主要依赖了 System.arraycopy() 方法实现的.所以需要了解一下这个方法如何使用.转载请注明出处:https://www.c ...