POJ 3616Milking Time
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
题解:
这个题目还是比较水的吧,设dp[i]表示选以i结尾的物品的最大价值。
那么dp[i]=max(dp[j]+v[i])(l[i]-r[j]>=休息时间)。 代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#define MAXN 2000
#define ll long long
using namespace std;
struct qvjian{
int l,r,v;
void read(){
scanf("%d%d%d",&l,&r,&v);
}
}a[MAXN*];
ll dp[MAXN];
int h,n,k; bool cmp(qvjian x,qvjian y){
return x.r<y.r;
} int main()
{
scanf("%d%d%d",&h,&n,&k);
for(int i=;i<=n;i++) a[i].read();
sort(a+,a+n+,cmp);
memset(dp,,sizeof(dp));
a[].r=-(<<);
for(int i=;i<=n;i++){
for(int j=i-;j>=;j--){
if(a[i].l-a[j].r>=k)
dp[i]=max(dp[i],dp[j]+a[i].v);
}
}
ll ans=;
for(int i=;i<=n;i++) ans=max(ans,dp[i]);
printf("%lld\n",ans);
return ;
}
POJ 3616Milking Time的更多相关文章
- POJ:3616-Milking Time
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12324 Accepted: 5221 Descrip ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- 【Offer】[29] 【顺时针打印矩阵】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字. 例如,如果输入如下矩阵:  则依次打印出数字1,2,3,4,8,12, ...
- 详细的漏洞复现:Shellshock CVE-2014-6271 CVE-2014-7169
目录 前言 漏洞原理 利用方式 复现过程 1. 环境准备 (1) 为容器配置固定IP地址 (2) 查看bash版本 2. 本地验证:测试镜像系统是否存在漏洞 3. 远程模拟验证(原理验证) (1) 查 ...
- [大数据学习研究]2.利用VirtualBox模拟Linux集群
1. 在主机Macbook上设置HOST 前文书已经把虚拟机的静态IP地址设置好,以后可以通过ip地址登录了.不过为了方便,还是设置一下,首先在Mac下修改hosts文件,这样在ssh时就不用输入ip ...
- SeekBar拖动条
seekbar拖动条,通过滑块的位置值的改变,来对某些数据进行调节,比如音量调节; 改变滑块的外观可以通过android:thumb属性完成 实例:拖动滑块改变图片透明度 <LinearLayo ...
- Stanford公开课《编译原理》学习笔记(1~4课)
目录 一. 编译的基本流程 二. Lexical Analysis(词法分析阶段) 2.1 Lexical Specification(分词原则) 2.2 Finite Automata (典型分词算 ...
- 手把手教你搭建Jenkins实现自动化部署Jar
centeros7 安装配置环境jdk1.8 1.先卸载centeros自带jdk rpm -qa | grep openjdk 查询出来的自带的openjdk 2.删除 rpm -e --nodep ...
- Java优化策略小积累
1.尽量避免大量使用静态变量 package com.cfang.jvm; public class Test2 { private static Test1 test1 = new Test1(); ...
- shiro+spring
公司自用的管理系统使用了shiro,但是对于这个登录页面跳转.登录的过程逻辑以及登录成功或者失败的跳转页面一直不理解,查看相关文档资料,整理出一些结果并本地调试测试,记录下备以后回顾之用. 对于spr ...
- SSM框架中测试单元的使用,spring整合Junit
测试类中的问题和解决思路 3.1.1 问题 在测试类中,每个测试方法都有以下两行代码: ApplicationContext ac = new ClassPathXmlApplicatio ...
- Loadrunner录制步骤及说明
做好业务准备,如环境配置.服务启动等 打开Virtual User Generator界面---->New---->选择协议,录制网页时一般选择Web(HTTP/HTML) Start R ...