Milking Time---poj3616
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 题目大意:
刚开始题目一直都不懂 到底不知道是让干啥呢 更不知道答案是怎么得来的
搜了好几个题解 最后知道了 他是说啥意思吧
就是给你m个挤奶的时间段和挤奶的量
就是这个人挤奶的话 必须是一个时段全都在挤奶 他挤过这段时间他必须休息r小时之后再开始下一次挤
最后求n个小时最大的挤奶量 分析:
就是dp 没啥好说的
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<stdlib.h> using namespace std; #define INF 0xfffffff
#define N 1100
struct node
{
int s,e,l;
}a[N]; int cmp(const void *x,const void *y)
{
struct node *c,*d;
c=(struct node *)x;
d=(struct node *)y;
if(c->e!=d->e)
return c->e-d->e;
else
return c->s-d->s;
} int main()
{
int n,m,r,dp[N];
while(scanf("%d %d %d",&n,&m,&r)!=EOF)
{
for(int i=;i<m;i++)
{
scanf("%d %d %d",&a[i].s,&a[i].e,&a[i].l);
}
qsort(a,m,sizeof(a[]),cmp);
for(int i=;i<m;i++)
{
dp[i]=a[i].l;
}
for(int i=;i<m;i++)
{
for(int j=;j<i;j++)
{
if(a[j].e+r<=a[i].s)
{
dp[i]=max(dp[i],dp[j]+a[i].l);
}
}
}
int Max=;
for(int i=;i<m;i++)
{
Max=max(Max,dp[i]);
}
printf("%d\n",Max);
}
return ;
}
Milking Time---poj3616的更多相关文章
- 动态规划 POJ3616 Milking Time
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...
- poj3616 Milking Time(状态转移方程,类似LIS)
https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...
- POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- POJ3616 Milking Time【dp】
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- POJ3616:Milking Time
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5682 Accepted: 2372 Desc ...
- poj-3616 Milking Time (区间dp)
http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...
- POJ3616 Milking Time 简单DP
注意0,1,.....,N是时间点,i~i+1是时间段 然后就是思路:dp[i]代表到时间点 i 获得的最大价值, 1:dp[i]=max(dp[i],dp[s-r]+e),表示有以s为开头,i为结尾 ...
- poj3616 Milking Time
思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- 【POJ - 3616】Milking Time(动态规划)
Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...
- POJ2455Secret Milking Machine[最大流 无向图 二分答案]
Secret Milking Machine Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11865 Accepted ...
随机推荐
- Oracle 11g r2 Enterprise Manager (EM) 中文页面调整为英文页面
Oracle 11g r2 Enterprise Manager (EM) 在中文语言环境下, 部分功能(如包含时间的查询数据库实例: orcl > 指导中心 > SQL 优化概要 ...
- 【转载】Hierarchal Temporal Memory (HTM)
最近在看机器学习,看能否根据已有的历史来预测Hardware的故障发生概率.下文是一篇很有意思的文章,转自 http://numenta.org/htm.html. NuPIC是一个开源项目,用来实现 ...
- HDU 5380 Travel with candy (贪心,单调队列)
题意: 有n+1个城市按顺序分布在同一直线上,现在需从0号城市按顺序走到n号城市(保证可达),从0号城市到i号城市需要消耗ai个糖果,每个城市都可以通过买/卖糖果来赚取更多的钱,价格分别是buyi和s ...
- PHP一句话后门过狗姿势万千之传输层加工
既然木马已就绪,那么想要利用木马,必然有一个数据传输的过程,数据提交是必须的,数据返回一般也会有的,除非执行特殊命令. 当我们用普通菜刀连接后门时,数据时如何提交的,狗狗又是如何识别的,下面结合一个实 ...
- pickle 两个使用小方法
def pickle_load(file_path): f = open(file_path,'r+') data = pickle.load(f) f.close() return data ...
- python基础一 day2
内容: 3%%s 输出:3%s 后面的全部转义 结果: 如果是因为执行break语句导致循环提前结束,就不会执行else. 单位换算: 编码方式: ascii unicode u ...
- Xgboost集成算法
集成算法思想: Xgboost基本原理: Xboost中是一个树(函数)接着一个树(函数)往里加,每加一个树都希望整体表达效果更好一些,即:目标函数逐步减小. 每加入一个函数,使目标函数逐渐减小,整体 ...
- Tomcat启动报错 ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization failed
背景: 在进行Spring Struts2 Hibernate 即SSH整合的过程中遇到了这个错误! 原因分析: Bean已经被加载了,不能重复加载 原来是Jar包重复了! 情形一: Tomcat ...
- PHP21 MVC
学习目标 MVC设计模式 单一入口机制 MVC的实现 MVC设计模式 Model(模型) 是应用程序中用于处理应用程序数据逻辑的部分.通常模型对象负责在数据库中存取数据. View(视图) 是应用程序 ...
- JavaEE-01 JSP动态网页基础
学习要点 B/S架构的基本概念 Web项目的创建和运行 JSP页面元素 MyEclipse创建和运行Web项目 Web程序调试 Web简史 web前端技术演进三阶段 WEB 1.0:信息广播. WEB ...