Milking Time

Time Limit: 1000MS    Memory Limit: 65536K

Total Submissions: 9459  Accepted: 3935

 

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

Source

 
有将近一个月没做题,练一下手感。
 //2017-05-16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int M = ;
int dp[M];
struct Milk
{
int bg, ed, eff;
bool operator<(Milk x) const{
return ed < x.ed;
}
}milk[M]; int main()
{
int n, m, r;
while(scanf("%d%d%d", &n, &m, &r)!=EOF)
{
memset(dp, , sizeof(dp));
for(int i = ; i < m; i++){
scanf("%d%d%d", &milk[i].bg, &milk[i].ed, &milk[i].eff);
}
sort(milk, milk+m);
int ans = ;
for(int i = ; i < m; i++){
if(milk[i].ed > n)break;
dp[i] = milk[i].eff;
for(int j = ; j < i; j++){
if(milk[i].bg-r >= milk[j].ed){
dp[i] = max(dp[i], dp[j]+milk[i].eff);//dp[i]表示到第i个区间的最大值
}else break;
}
if(dp[i] > ans)ans = dp[i];
}
printf("%d\n", ans);
} return ;
}

POJ3616(KB12-R dp)的更多相关文章

  1. POJ3616 Milking Time —— DP

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

  2. POJ3616【基础DP】

    //因为同一点结束的时间段会有多个,这里没考虑: //无限wa: const int N=1e6+7; int b[N]; LL a[N]; LL dp[N]; struct asd{ int s; ...

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

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

  4. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  5. poj3417 LCA + 树形dp

    Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4478   Accepted: 1292 Descripti ...

  6. 【BZOJ-4380】Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  7. HDU 5945 / BestCoder Round #89 1002 Fxx and game 单调队列优化DP

    Fxx and game 问题描述   青年理论计算机科学家Fxx给的学生设计了一款数字游戏. 一开始你将会得到一个数\:XX,每次游戏将给定两个参数\:k,tk,t, 任意时刻你可以对你的数执行下面 ...

  8. bzoj-4518 4518: [Sdoi2016]征途(斜率优化dp)

    题目链接: 4518: [Sdoi2016]征途 Description Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地 ...

  9. bzoj-1096 1096: [ZJOI2007]仓库建设(斜率优化dp)

    题目链接: 1096: [ZJOI2007]仓库建设 Description L公司有N个工厂,由高到底分布在一座山上.如图所示,工厂1在山顶,工厂N在山脚.由于这座山处于高原内陆地区(干燥少雨),L ...

  10. CF149D. Coloring Brackets[区间DP !]

    题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...

随机推荐

  1. IO、NIO、AIO

    一. IO 传统的IO是同步阻塞模式,数据的读取与写入会阻塞在一个线程内等待其完成. 主要面向字节流编程.(流是单向的) 二. NIO NIO支持同步非阻塞模式,在进行IO调用后,然后去 轮询调用结果 ...

  2. django 之 发送邮箱

    发送邮箱的话首先在settings文件里写下边的这些设置: #邮件服务配置文件 SSL认证,验证 EMAIL_USE_SSL = True #邮箱服务 EMAIL_HOST = 'smtp.qq.co ...

  3. odoo开发笔记 -- odoo和postgresql数据库导入相关

    odoo数据库 导入.导出 首先odoo框架下postgresql数据库中,表结构的存储方式: 存在id(小写),并没有所谓的外部ID 例如数据库中的国家表:模块名_tb_country   (注意: ...

  4. odoo开发笔记-tree列表视图拖拽排序

    odoo列表tree视图 拖拽排序 实现效果: 实现方式: 模型中定义字段: class CusYourModel(models.Model): """ 你的模型 &qu ...

  5. (转) 面向对象设计原则(二):开放-封闭原则(OCP)

    原文:https://blog.csdn.net/tjiyu/article/details/57079927 面向对象设计原则(二):开放-封闭原则(OCP) 开放-封闭原则(Open-closed ...

  6. Windows 安装Rabbitmq

    Rabbitmq是基于erlang开发的消息队列,客户端支持主流的开发语言(java.C#.Python等). 环境:windows server 2012(x64) 1.下载安装 http://ww ...

  7. javascript实现代码高亮-wangHighLighter.js

    1. 引言 (先贴出wangHighLighter.js的github地址:https://github.com/wangfupeng1988/wangHighLighter注意,程序和使用说明的更新 ...

  8. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(七):集成 Druid 数据源

    数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据库连接遗漏 ...

  9. Tensorflow应用之LSTM

    学习RNN时原理理解起来不难,但是用TensorFlow去实现时被它各种数据的shape弄得晕头转向.现在就结合一个情感分析的案例来了解一下LSTM的操作流程. 一.深度学习在自然语言处理中的应用 自 ...

  10. kafka-java客户端连接

    使用java客户端, kafkaproducer, kafkaconsumer进行kafka的连接 注: 0.10 版本之后, 连接kafka只需要brokerip即可, 不需要zookeeper的信 ...