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秒开 ...
随机推荐
- Locale
1. Locale 概述 2. Windows 区域设置 3 Linux Locale 3.1 Linux Locale 语言环境名称格式 3.2 常用区域描述(简写)日期习惯 3.3 日期显示格式 ...
- Linux centosVMware LNMP架构介绍、MySQL安装、PHP安装、Nginx介绍
一. LNMP架构介绍 和LAMP不同的是,提供web服务的是Nginx 并且php是作为一个独立服务存在的,这个服务叫做php-fpm Nginx直接处理静态请求,动态请求会转发给php-fpm ...
- [经验] Java 使用 netty 框架, 向 Unity 客户端的 C# 实现通信 [1]
这是一个较为立体的思路吧 首先是技术选型: 前端 : HTML5 + jQuery ,简单暴力, 不解释 服务端 : Spring Boot + Netty + Redis/Cache 客户端 ...
- Eclipse java SE版本解决无法新建web项目问题
最近工作要涉及web开发,之前下载的java SE (我的是indigo) 版本默认无法新建web项目,也就是找不到Dynamic Web ,在网上看了些解决办法,最终却是解决了问题,说到底就是安装一 ...
- 【快学springboot】9.使用 @Transactional 注解配置事务管理
介绍 springboot对数据库事务的使用非常的方便,只需要在方法上添加@Transactional注解即可.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的 ...
- java并发:join源码分析
join join join是Thread方法,它的作用是A线程中子线程B在运行之后调用了B.join(),A线程会阻塞直至B线程执行结束 join源码(只有继承Thread类才能使用) 基于open ...
- 前端Cannot read property 'disabled' of null 问题解决
就是在项目中,控制台一直在报这个错,一直没找到是什么问题, 后来经过一番排查,发现是 因为在页面中使用了el-dropdown,但是在这个标签里面没有设置它的子元素,所以会报错,解决的方法就是在el- ...
- Vue - 路由守卫使用
import Vue from 'vue' import VueRouter from 'vue-router' import Home from '../views/Home.vue' Vue.us ...
- struts2--验证器
1.输入验证: --struts2提供了一些基于Xwork Validation Framework的内建验证程序,使用这些验证程序不需要变编程,只要在一个XML文件里进行声明,声明的内容如下: &g ...
- 「CF10D」LCIS
传送门 Luogu 解题思路 首先考虑怎么求方案,这样才可能会输出方案. 考虑 \(\text{DP}\). 设 \(f[i][j]\) 表示在 \(a\) 序列中选择一个 \([1...i]\) 的 ...