#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: 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

思路很简单,但感觉不是很好想,一开始想成背包问题了= =!

言归正传,这题就先按开始时间排序,按最长上升序列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的更多相关文章

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

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

  2. POJ3616 Milking Time —— DP

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

  3. POJ3616 Milking Time【dp】

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

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

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

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

  6. poj3616 Milking Time

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

  7. 《挑战程序设计竞赛》2.3 动态规划-基础 POJ3176 2229 2385 3616 3280

    POJ3176 Cow Bowling 题意 输入一个n层的三角形,第i层有i个数,求从第1层到第n层的所有路线中,权值之和最大的路线. 规定:第i层的某个数只能连线走到第i+1层中与它位置相邻的两个 ...

  8. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

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

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

随机推荐

  1. Hadoop学习笔记二

    一.设置无密码sudo权限,不用在普通用户和root用户间来回切换 chmod u+w /etc/sudoers vim /etc/sudoers #首行添加如下的内容: hadoop ALL=(ro ...

  2. Java多线程基础(一)

    一个简单的多线程的例子: package multiThread; public class BasicThread implements Runnable{ private int countDow ...

  3. 洛谷 [P1118] IOI1994 数字三角形

    简单dfs 我们注意到,题目中的运算方式与杨辉三角极其相似,所以说本题实际上是一道加权的杨辉三角,搜索系数 #include <iostream> #include <cstdio& ...

  4. BZOJ 2194 [快速傅里叶变换 卷积]

    题意:请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非负整数. 卷积 ( ...

  5. 微信小程序中不同页面间的参数传递

    从样式页面WXML向逻辑页面JS传递点击事件的响应函数中传递参数 <!--此为样式页面--> <block wx:for="{{postList}}" wx:fo ...

  6. 乞丐版servlet容器第1篇

    本系列参照pkpk1234大神的BeggarServletContainer,具体请访问:https://github.com/pkpk1234/BeggarServletContainer. 一步一 ...

  7. python爬虫(7)——BeautifulSoup

    今天介绍一个非常好用的python爬虫库--beautifulsoup4.beautifulsoup4的中文文档参考网址是:http://beautifulsoup.readthedocs.io/zh ...

  8. 利用Jsonp实现跨域请求,spring MVC+JQuery

    1 什么是Jsonp? JSONP(JSON with Padding)是数据格式JSON的一种"使用模式",可以让网页从别的网域要数据.另一个解决这个问题的新方法是跨来源资源共享 ...

  9. Java集合中的Map接口

    jdk1.8.0_144 Map是Java三种集合中的一种位于java.util包中,Map作为一个接口存在定义了这种数据结构的一些基础操作,它的最终实现类有很多:HashMap.TreeMap.So ...

  10. Shiro 核心功能案例讲解 基于SpringBoot 有源码

    Shiro 核心功能案例讲解 基于SpringBoot 有源码 从实战中学习Shiro的用法.本章使用SpringBoot快速搭建项目.整合SiteMesh框架布局页面.整合Shiro框架实现用身份认 ...