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 ...
随机推荐
- 微信小程序开发系列六:微信框架API的调用
微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的视图设计 微信小程序开发系列三:微信小程序的调试方法 微信小程序开发系列四:微信小程序 ...
- 设计模式、SOLID原则:组件与联系
组件原则 - SRP The Single Responsibility Principle 单一责任原则 当需要修改某个类的时候原因有且只有一个.换句话说就是让一个类只做一种类型的责任,当这个类需要 ...
- strict说明
- 洛谷P1421 小玉买文具
这道题其实就是编程最基础的逻辑,没什么好讲的输入,输出就完了,非常简单! code: #include<cstdio> #include<iostream> using nam ...
- 2019天梯赛练习题(L2专项练习)
7-2 列出连通集 (25 分) 给定一个有N个顶点和E条边的无向图,请用DFS和BFS分别列出其所有的连通集.假设顶点从0到N−1编号.进行搜索时,假设我们总是从编号最小的顶点出发,按编号递增的顺序 ...
- 使用Spring IoC进行Bean装配
Spring概述 Spring的设计严格遵从的OCP(开闭原则),保证对修改的关闭,也就是外部无法改变spring内部的运行流程:提供灵活的扩展接口,也就是可以通过extends,implements ...
- 用python的Requests库模拟http请求
一.先了解几个重要的http请求头或响应头信息 Request Headers: Host: 描述请求将被发送的目的地,包括,且仅仅包括域名和端口号. Origin: 说明请求从哪里发起的,包括,且仅 ...
- mysql 删除恢复
一.模拟误删除数据表的恢复 1 二进制日志功能启用 vim /etc/my.cnf [mysqld] log-bin 2 完全备份 mysqldump -A -F --master-data=2 - ...
- python-列表数据类型内置方法
1 列表数据类型(必考) 1.1 用途:兴趣爱好,多个女朋友 1.2 定义方式:[]内用逗号隔开多个元素,多个元素可以是任意数据类型 fangping_boy_friend_list=['ruixin ...
- CentOS 7 设置开机自启动
创建脚本: #!/bin/bash echo "hello!" # 启动虚拟环境 cd /data/env/crmenv/bin/ source activ ...