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 ( ≤ N ≤ ,,) hours (conveniently labeled ..N-) so that she produces as much milk as possible.

Farmer John has a list of M ( ≤ M ≤ ,) possibly overlapping intervals in which he is available for milking. Each interval i has a starting hour ( ≤ starting_houri ≤ N), an ending hour (starting_houri < ending_houri ≤ N), and a corresponding efficiency ( ≤ efficiencyi ≤ ,,) 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 ( ≤ 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 : Three space-separated integers: N, M, and R
* Lines ..M+: Line i+ describes FJ's ith milking interval withthree space-separated integers: starting_houri , ending_houri , and efficiencyi

Output

* Line : The maximum number of gallons of milk that Bessie can product in the N hours

Sample Input


Sample Output


Source

 
 
 
dp,注意初始化,

for(int i=1;i<=m;i++){
dp[i]=cows[i].c;
}

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stdlib.h>
using namespace std;
#define N 1000006
#define M 1006
int n,m,r;
struct Node{
int s,e;
int c;
}cows[M];
bool cmp(Node a,Node b){
if(a.s!=b.s)
return a.s<b.s;
return a.e<b.e;
}
int dp[M];//dp[i]表示取到第i段时间段时的最大值
int main()
{
while(scanf("%d%d%d",&n,&m,&r)==){
for(int i=;i<=m;i++){
scanf("%d%d%d",&cows[i].s,&cows[i].e,&cows[i].c);
}
sort(cows+,cows+m+,cmp);
memset(dp,,sizeof(dp));
for(int i=;i<=m;i++){
dp[i]=cows[i].c;
}
//dp[1]=cows[1].c;
int ans=;
for(int i=;i<=m;i++){
for(int j=;j<i;j++){
if(cows[i].s>=cows[j].e+r){
dp[i]=max(dp[i],dp[j]+cows[i].c);
}
}
ans=max(dp[i],ans);
// printf("---%d\n",ans);
}
printf("%d\n",ans);
}
return ;
}

poj 3616 Milking Time(dp)的更多相关文章

  1. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  2. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  3. POJ 3616 Milking Time(加掩饰的LIS)

    传送门: http://poj.org/problem?id=3616 Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  4. POJ 3616 Milking Time 【DP】

    题意:奶牛Bessie在0~N时间段产奶.农夫约翰有M个时间段可以挤奶,时间段f,t内Bessie能挤到的牛奶量e.奶牛产奶后需要休息R小时才能继续下一次产奶,求Bessie最大的挤奶量.思路:一定是 ...

  5. POJ 3858 Hurry Plotter(DP)

    Description A plotter is a vector graphics printing device that connects to a computer to print grap ...

  6. Milking Time(DP)

    个人心得:一开始自己找状态,是这么理解的,只要前面一个满足就等于此时的值加上d(n-1),否则就是不挖此时的比较d(n-1)和 d(n-2)+cost,不过仔细一想忽略了很多问题,你无法确定n-2和此 ...

  7. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  8. POJ 3616 Milking Time(最大递增子序列变形)

    题目链接:http://poj.org/problem?id=3616 题目大意:给你时间N,还有M个区间每个区间a[i]都有开始时间.结束时间.生产效率(时间都不超过N),只能在给出的时间段内生产, ...

  9. POJ 3616 Milking Time ——(记忆化搜索)

    第一眼看是线段交集问题,感觉不会= =.然后发现n是1000,那好像可以n^2建图再做.一想到这里,突然醒悟,直接记忆化搜索就好了啊..太蠢了.. 代码如下: #include <stdio.h ...

随机推荐

  1. npm 和 bower的区别

    npm和bower在功能上有一定的重合,但不是互斥关系,可以在项目中同时运用.区别在于npm在设计之初就采用了的是嵌套的依赖关系树.一个普通的前端包的依赖树比较长,npm 会将开发环境一起下载下来,  ...

  2. adb网络调试

    对Android比较熟悉的开发人员,对adb通过USB(USB连接Android设备)调试Android设备应该不会陌生,因为大部分资料都是这样做的.但是假如你的Android设备没有USB口,只有网 ...

  3. select与epoll分析

    关于select与epoll的区别,网上的文章已是一大堆.不过别人的终究是别人的,总得自己去理解才更深刻.于是在阅读了大量的文章后,再装模作样的看下源码,写下了自己的一些理解. 在开始之前,要明白li ...

  4. POJ 3450 Corporate Identity (KMP+暴搞)

    题意: 给定N个字符串,寻找最长的公共字串,如果长度相同,则输出字典序最小的那个. 找其中一个字符串,枚举它的所有的字串,然后,逐个kmp比较.......相当暴力,可二分优化. #include & ...

  5. Android 打造任意层级树形控件 考验你的数据结构和设计

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/40212367,本文出自:[张鸿洋的博客] 1.概述 大家在项目中或多或少的可能会 ...

  6. python 之 Paramiko学习

    paramiko模块,基于SSH用于连接远程服务器并执行相关操作. 一.安装 pip3 install paramiko 二.使用 SSHClient 用于连接远程服务器并执行基本命令 基于用户名密码 ...

  7. C# KeyValuePair<TKey,TValue>与Container

    KeyValuePair<TKey,TValue>  KeyValuePair<TKey,TValue>是一个结构体,相当于C#一个Map类型的对象,可以通过它记录一个键/值对 ...

  8. Java的Object对象

    Object对象是除了基础对象之外,所有的对象都需要继承的父对象,包括数组也继承了Object Object里面的关键函数罗列如下: clone();调用该函数需要实现 Cloneable,否则会抛出 ...

  9. JAVA与JSON的序列化、反序列化

    package com.linkage.app.memcache; import java.util.HashMap;import java.util.Map.Entry; import net.sf ...

  10. Objective-C 字符串

    #import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char * argv[]) { ...