POJ3616:Milking Time
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5682 | Accepted: 2372 |
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
题意:在各段时间之内产牛奶的数量不同,有休息时间,过了休息时间之后才能继续产牛奶。问总共能产多少牛奶。
代码:
#include <iostream>
#include <algorithm>
using namespace std; struct node{
int start;
int end;
int ef;
}eff[1005]; int dp[1000005];
bool cmp(struct node node1,struct node node2)
{
if(node1.start==node2.start)
return node1.end<node2.end;
else
return node1.start<node2.start;
} int main()
{
int N,M,R;
cin>>N>>M>>R; int i,j;
for(i=1;i<=M;i++)
{
cin>>eff[i].start>>eff[i].end>>eff[i].ef;
eff[i].end+=R;
}
sort(eff+1,eff+M+1,cmp); memset(dp,0,sizeof(dp)); for(i=1;i<=M;i++)
{
dp[eff[i].end]=eff[i].ef;
} int max_i;
for(i=1;i<=M;i++)
{
max_i=0;
for(j=1;j<i;j++)
{
if(eff[j].end<=eff[i].start)
{
if(dp[eff[j].end]>max_i)
{
max_i=dp[eff[j].end];
}
}
}
dp[eff[i].end]=max(max_i+eff[i].ef,dp[eff[i].end]);
}
max_i=0;
for(i=1;i<=M;i++)
{
if(dp[eff[i].end]>max_i)
{
max_i=dp[eff[i].end];
}
}
cout<<max_i<<endl; return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ3616:Milking Time的更多相关文章
- POJ 2185 Milking Grid [二维KMP next数组]
传送门 直接转田神的了: Milking Grid Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6665 Accept ...
- java web 开发三剑客 -------电子书
Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...
- 所有selenium相关的库
通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...
- Optimal Milking 分类: 图论 POJ 最短路 查找 2015-08-10 10:38 3人阅读 评论(0) 收藏
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 13968 Accepted: 5044 Case ...
- POJ2112:Optimal Milking(Floyd+二分图多重匹配+二分)
Optimal Milking Time Limit: 2000MS Memory Limit: 30000K Total Submissions: 20262 Accepted: 7230 ...
- POJ3616 Milking Time —— DP
题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- 题解报告:poj 2185 Milking Grid(二维kmp)
Description Every morning when they are milked, the Farmer John's cows form a rectangular grid that ...
- POJ3616 Milking Time【dp】
Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...
- 洛谷 P1204 [USACO1.2]挤牛奶Milking Cows Label:模拟Ex 74分待查
题目描述 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开 ...
随机推荐
- Linux centosVMware Nginx安装、 默认虚拟主机、Nginx用户认证、Nginx域名重定向
一. Nginx安装 cd /usr/local/src wget http://nginx.org/download/nginx-1.12.1.tar.gz 版本在http://nginx.org/ ...
- Windows 控制台命令笔记
1. cmd中输出中文乱码问题: CHCP是一个计算机指令,能够显示或设置活动代码页编号. C:\windows\system32>CHCP 活动代码页: 936 原因是我们使用了GBK编码,下 ...
- Java入门程序“hello,world!”
1.程序开发步骤说明 开发环境已经搭建完毕,可以开发我们第一个Java程序了. Java程序开发三步骤:编写.编译.运行.(图片介绍) 2.编写Java程序 新建一个普通的记事本,给其命名为Hel ...
- C#二维数组的初始化和存取
static void Main(string[] args) { ,]; ; j < ; j++) { strings[j, ] = $"{j}.0"; strings[j ...
- centos 访问win共享
yum install samba 安装samba (其实我们只用到samba里面的winbind以便我们能够用windows机器的名称找到该机器的网络地址,在下面叙述的过程会用到.而且也要确定在 w ...
- Linux 运维常用命令
参考: https://segmentfault.com/a/1190000009745139 http://blog.51cto.com/xuqq999/774714 .查看有多少个IP访问: aw ...
- PHP中的异常知识
一.绪 首先明确一点:异常和错误不是一回事. 一个异常(Exception)是一个程序执行过程中出现的一个例外或是一个事件,它中断了正常指令的运行,跳转到其他程序模块继续执行. 基本格式: try { ...
- JetBrains IntelliJ IDEA(IJ)v2019.3.3/3.1/3.2/3.4/3.5 for mac/windows/linux 详细安装破解教程
手欠升级了IntelliJ IDEA到2019.3.3,原来的破解不可用,IntelliJ IDEA 2019.3.3破解办法如下,为方便自己使用记录下.======================= ...
- Vmware tools变灰不能点击的问题
1. 挂载镜像文件,虚拟机->设置->硬件->CD/DVD.右边“连接”下面选择“使用IOS镜像文件”,浏览选择虚拟机包目录下面linux.iso 2. 挂载成功后,在虚拟机右下角c ...
- luogu P2762 太空飞行计划问题
好像是最大权闭合图,也就是最大流最小割啦,找出最大流的路径输出,这题如何建模呢,一样的先设源点和汇点,源点向每个计划连capacity为赞助数的边,每个计划连相应装置capacity为无穷的边,每个装 ...