POJ - 3616 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 Nhours
Sample Input
12 4 2
1 2 8
10 12 19
3 6 24
7 10 31
Sample Output
43 题意:
给出m个取奶时间段和该时间段内的取奶量,每次取奶之后需要休息r个时间段,问最大取奶量
思路:
按时间段右端点排序。
dp[i]表示第i个时间段取奶之后的最大取奶量。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int n,m,r;
struct node{
int l,r,v;
}a[];
int dp[maxn];
bool cmp(node a,node b){
return a.r<b.r;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); scanf("%d%d%d",&n,&m,&r);
for(int i=;i<=m;i++){
scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].v);
}
sort(a+,a++m,cmp);
int ans=;
for(int i=;i<=m;i++){
dp[i]=a[i].v;
for(int j=;j<i;j++){
if(a[j].r+r<=a[i].l){dp[i]=max(dp[i],dp[j]+a[i].v);}
}
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
return ;
}
POJ - 3616 Milking Time (动态规划)的更多相关文章
- POJ 3616 Milking Time(加掩饰的LIS)
传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- 动态规划:POJ 3616 Milking Time
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> ...
- POJ 3616 Milking Time (排序+dp)
题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次 ...
- poj 3616 Milking Time
Milking ...
- POJ 3616 Milking Time(最大递增子序列变形)
题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...
- poj 3616 Milking Time (基础dp)
题目链接 http://poj.org/problem?id=3616 题意:在一个农场里,在长度为N个时间可以挤奶,但只能挤M次,且每挤一次就要休息t分钟: 接下来给m组数据表示挤奶的时间与奶量求最 ...
- poj 3616 Milking Time(dp)
Description Bessie ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as ...
- POJ 3616 Milking Time 简单DP
题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量. 详见代码 ...
- POJ 3616 Milking Time (字符串DP)
题意:找元素关于对角线左或右对称的最大矩阵 思路:左右对角线只需要遍历一条就可以了.只要当前点往上遍历和往后遍历一样就可以. #include<iostream> #include< ...
随机推荐
- Tomcat开启SSL协议支持
一.生成keyStore 要使用ssl connector,必须先创建一个keystore.他包含了服务器中被客户端用于验证服务器的数字证书.一旦客户端接受了这个证书,客户端就可以使用public k ...
- 中科曙光I620-G15服务器登录密码破解
服务器型号:中科曙光I620-G15服务器 系统:windowsserver2008R2 单位:保密 服务器登录密码忘记了,进不去桌面,后来在我们云修网工程师的指导下,顺利绕过密码登录系统,然后修改系 ...
- ThinkPad E470笔记本电脑无声音、无线wifi功能(灰色)
最近有同事找我看他的笔记本没有wifi,型号是ThinkPadE470 ,上网搜了下提问的挺多,写一个看看有什么帮助没 看了下笔记本wifi标志是灰色显示只有飞行模式,启用了一下热键 fn+F3 没什 ...
- HybridStart混合应用开发框架
转自我的博客,原文地址:http://refined-x.com/2017/06/26/%E5%9F%BA%E4%BA%8EAPICloud%E7%9A%84%E6%B7%B7%E5%90%88%E5 ...
- UVALive - 3211 - Now or later(图论——2-SAT)
Problem UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sampl ...
- 解决OrangePi 耳机孔没有声音
遇到过插入耳机后没有声音,解决步骤如下: 打开终端TERMINAL(LUBUNTU按CTRL+ALT+T,MATE选SYSTERM ADMINSTRATION-MATER TERMINAL),SSH登 ...
- 在Unity使文字变色
using UnityEngine;using System.Collections;using UnityEngine.UI; public class ShipIntro : MonoBehavi ...
- SkylineGlobe7.0.1版本 通过鼠标左右平移模型对象
帮同事写了一段测试代码,如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...
- C# FileSystemWatcher 并发
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 【原创】分布式事务之TCC事务模型
引言 在上篇文章<老生常谈--利用消息队列处理分布式事务>一文中留了一个坑,今天来填坑.如下图所示 如果服务A和服务B之间是同步调用,比如服务C需要按流程调服务A和服务B,服务A和服务B要 ...