动态规划 POJ3616 Milking Time
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- struct cow
- {
- int start;
- int endd;
- int price;
- };
- bool cmp(cow a,cow b)
- {
- return a.start<b.start;
- }
- int main()
- {
- int n,m,r;
- cow a[1005];
- cin>>n>>m>>r;
- int i,j;
- for(i=0;i<m;i++)
- {
- cin>>a[i].start>>a[i].endd>>a[i].price;
- a[i].endd+=r;
- }
- sort(a,a+m,cmp);
- int dp[1005]={0};
- for(i=0;i<m;i++)
- {
- dp[i]=a[i].price;
- for( j=0;j<i;j++)
- {
- if(a[i].start>=a[j].endd)
- {
- dp[i]=max(dp[i],dp[j]+a[i].price);
- }
- }
- }
- cout<<*max_element(dp,dp+m)<<endl;
- return 0;
- }
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
思路很简单,但感觉不是很好想,一开始想成背包问题了= =!
言归正传,这题就先按开始时间排序,按最长上升序列O(n^2)的方法解,状态转移方程为dp[i]=max(dp[i],dp[j]+a[i].price),0<=j<i&&a[i].start>=a[j].end.
动态规划 POJ3616 Milking Time的更多相关文章
- 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 ...
- 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 ...
- 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280
POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...
- 「kuangbin带你飞」专题十二 基础DP
layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...
- 【POJ - 3616】Milking Time(动态规划)
Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...
随机推荐
- 网络搬砖是件苦力活 CMS推荐GHOS博客程序
搬砖不是技术活,而是苦力(bi)活,富有技术含量的苦力活说不定就是一门可以持续的生意. 我们不生产内容,我们只是互联网的内容搬运工,这是大部分不具备原创能力个人站长的心声.虽然原创能力不够,但是服务目 ...
- IOLI-crackme0x01-0x05 writeup
上一篇开了个头, 使用Radare2并用3中方法来解决crackme0x00, 由于是第一篇, 所以解释得事无巨细, 今天就稍微加快点步伐, 分析一下另外几个crackme. 如果你忘记了crackm ...
- MySQL Community Server 5.7安装详细步骤
mysql社区版安装配置步骤较繁琐,几经搜索之后才成功安装,此文将所有的安装步骤及安装过程中遇到的问题进行了总结 1. 下载MySQL社区版 最新版下载地址:https://dev.mysql ...
- 新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD Application Key
新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD应用的Key 前篇讲过有一个面向公众的Runbook库,社区和微软一直往其中加入新的Runbook, ...
- python matplotlib 播放图片变化过程
最近想将原图片和处理后的图片放在一起观察图片的变化过程.但是网上并么有找到有用的示例代码,所以粘出来和大家分享一下. import numpy as np import matplotlib.pypl ...
- 给Ocelot做一个Docker 镜像
写在前面 在微服务架构中,ApiGateway起到了承前启后,不仅可以根据客户端进行分类,也可以根据功能业务进行分类,而且对于服务调用服务也起到了很好的接口作用.目前在各个云端中,基本上都提供了Api ...
- elk安装配置
ELK介绍 官网https://www.elastic.co/cn/ 中文指南https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/det ...
- mysql 在一个实例运行情况下再搭建一个实例
配置mysql服务 详细步骤,请参考(http://study.lishiming.net/chapter17.html#mysql), 阿铭只把简单步骤写一下. 根据阿铭提供的地址,假如你已经搭建好 ...
- shiro进行散列算法操作
shiro最闪亮的四大特征:认证,权限,加密,会话管理 为了提高应用系统的安全性,这里主要关注shiro提供的密码服务模块: 1.加密工具类的熟悉 首先来个结构图,看看shiro提供了哪些加密工具类: ...
- Mysql 远程登录及常用命令
第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uro ...