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: NM, 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的更多相关文章

  1. 动态规划 POJ3616 Milking Time

    #include <iostream> #include <cstdio> #include <algorithm> using namespace std; st ...

  2. poj3616 Milking Time(状态转移方程,类似LIS)

    https://vjudge.net/problem/POJ-3616 猛刷简单dp的第一天第二题. 这道题乍一看跟背包很像,不同的在于它是一个区间,背包是定点,试了很久想往背包上套,都没成功. 这题 ...

  3. POJ3616 Milking Time —— DP

    题目链接:http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. POJ3616 Milking Time【dp】

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  5. POJ3616:Milking Time

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5682   Accepted: 2372 Desc ...

  6. poj-3616 Milking Time (区间dp)

    http://poj.org/problem?id=3616 bessie是一头工作很努力的奶牛,她很关心自己的产奶量,所以在她安排接下来的n个小时以尽可能提高自己的产奶量. 现在有m个产奶时间,每个 ...

  7. 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为结尾 ...

  8. poj3616 Milking Time

    思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  9. 【POJ - 3616】Milking Time(动态规划)

    Milking Time 直接翻译了 Descriptions 贝茜是一个勤劳的牛.事实上,她如此​​专注于最大化她的生产力,于是她决定安排下一个N(1≤N≤1,000,000)小时(方便地标记为0. ...

  10. POJ2455Secret Milking Machine[最大流 无向图 二分答案]

    Secret Milking Machine Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11865   Accepted ...

随机推荐

  1. Javaweb学习笔记2—Tomcat和http协议

      今天来讲javaweb的第二个阶段学习. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps:我的思维是用的xMind画的,如果你对我的思维导图感兴趣并且想看到你们跟详细的备注信息,请点击下 ...

  2. Android内存泄露(全自动篇)

    写了可执行文件启动器Launcher.jar及一些批处理,通过它们就可以自动的以一定的时间间隔提取Hprof和进程的内存信息: 一.需要的库 可执行文件启动器:lib\Launcher.jar 注:关 ...

  3. 洛谷 P2894 [USACO08FEB]酒店Hotel

    题目描述 The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a ...

  4. Android(java)学习笔记181:多媒体之图片画画板案例

    1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...

  5. Linux常用的操作指令

    1.pwd-显示当前所在位置 2.cd-进入当前目录 3.cd..-返回上一级目录 4..ls命令参数选项有很多,ls也是经常使用到的命令.如果不清楚命令的使用方式可以直接 ls --help来查看 ...

  6. 爬虫学习之第一次获取网页内容及BeautifulSoup处理

    from urllib.request import urlopen from urllib.request import HTTPError from bs4 import BeautifulSou ...

  7. 第 6 章 Cinder - 061 - Boot from Volume

    Boot from Volume Volume 除了可以用作 instance 的数据盘,也可以作为启动盘(Bootable Volume). 打开 instance 的 launch 操作界面. 这 ...

  8. CentOS7.6 修改密码

    一.重启系统,在开机过程中,按下键盘上的e,进入编辑模式   三.将光标一直移动到 LANG=en_US.UTF-8 后面,空格,再追加init=/bin/sh.这里特别注意,需要写在UTF-8后,保 ...

  9. p1036 选数(不详细勿看,递归)

    题目:传送门 这题,不会做,而且看了好久才看懂题解的,然后在题解的基础上补了一个 if(start>end) return 0 感觉这样对于我更直观 转载自:大神博客的传送门,点击进入 先声明, ...

  10. 牛客OI赛制测试赛2 A 无序组数

    链接:https://www.nowcoder.com/acm/contest/185/A来源:牛客网 题目描述 给出一个二元组(A,B) 求出无序二元组(a,b) 使得(a|A,b|B)的组数 无序 ...