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 ...
随机推荐
- k8s集群之上游dns--dnsmasq,统一管理kubernetes的dns解析
1.概述 首先部署好kubernetes集群并采用Coredns进行解析,这样集群内部的服务都能通过内部域名进行访问.但是集群内部的coredns与物理机的dns解析不完全统一,coredns不能解析 ...
- CMMI三个过程域的流程及达到特定目标、共性目标的要求(RD需求管理过程,PI产品集成过程,TS技术解决方案)
RD需求管理过程 通过面谈的方式获取相关干系人关于产品生命周期各阶段的需求.期望,限制条件,接口 将相关干系人的需求.期望,限制条件,接口转化成用户需求说明书 依据客户需求,确定产品或产品组件需求,形 ...
- 微信小程序中this指向作用域问题this.setData is not a function报错
在微信小程序中我们一般通过以下方式来修改data中的数据 this.setData({ index1: e.detail.value }) 比如在函数里面修改数据 bindFaChange1: fun ...
- Java基础之 运算符
前言:Java内功心法之运算符,看完这篇你向Java大神的路上又迈出了一步(有什么问题或者需要资料可以联系我的扣扣:734999078) 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,J ...
- javascript Uncaught ReferenceError: 方法名 is not defined
前言: 那天我犯了这样一个低级错误,如果按照这样下去,根本在这条路上走不远.错的太离谱,把代码拿出来自己笑笑,等摆脱菜鸟之名的时候再回来好好的告诉自己,都是这么过来的,原来以前我菜的这么离谱.. 错误 ...
- VUE + ElementUI 从搭建到运行
版权声明:本文为博主原创文章,欢迎转载,转载请注明作者.原文超链接 前言:本文简洁的描述VUE + ElementUI 从搭建到运行,可以根据本文先搭建出可运行的项目,然后再详细回顾每个步骤所做的事: ...
- Docker版本变化和新版安装
Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施.容器 ...
- windows上使用tensorboard
因为我的环境变量设置的不是python3.5,所以走了一些弯路. 启动tensorboard后,graphs里总是什么都没有 最后再stackoverflow里找到答案 https://stackov ...
- java多线程关键字volatile、lock、synchronized
--------------------- 本文来自 旭日Follow_24 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/xuri24/article/detail ...
- 【20】策略者模式(Strategy Pattern)
一.引言 本文要介绍的策略模式也就是对策略进行抽象,策略的意思就是方法,所以也就是对方法的抽象,下面具体分享下我对策略模式的理解. 二.策略者模式介绍 2.1 策略模式的定义 在现实生活中,策略模式的 ...