POJ 3616 Milking Time
Milking Time
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15650 Accepted: 6644 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: 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 题目比较简单直接上代码:
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct obj{
long long int st,en,val;
} ob[1050];
long long int dp[1050];
bool cmp(obj a,obj b)
{
if(a.st==b.st) return a.en<b.en;
return a.st<b.st;
}
int main()
{
long long int cap,lis,re,tem1,tem2,ans;
while(cin>>cap>>lis>>re){
ans=0;
memset(dp,0,sizeof(dp));
for(int i=1;i<=lis;i++) scanf("%d%d%d",&ob[i].st,&ob[i].en,&ob[i].val);
sort(ob+1,ob+lis+1,cmp);
for(int i=1;i<=lis;i++){
tem1=tem2=0;
dp[i]=ob[i].val;
for(int t=i;t>=1;t--){
if(ob[i].st>=ob[t].en+re)
dp[i]=max(dp[i],dp[t]+ob[i].val);
ans=max(ans,dp[i]);
}
}
// for(int i=1;i<=lis;i++) cout<<dp[i]<<' ';
printf("%ldn",ans);
}
return 0;
}
- 挖洞经验 | 看我如何利用SAML漏洞实现Uber内部聊天系统未授权登录
- 使用ichartjs生成图表
- 使用angular4和asp.net core 2 web api做个练习项目(四)
- list.add(),向List集合插入对象报空指针异常
- 使用angular4和asp.net core 2 web api做个练习项目(三)
- 即学即用系列一:纯函数
- Java之StringBuffer,StringBuilder,Math,Date,SimpleDateFormat,UUID,File
- React编程思想
- 前台分页,以及类别选择
- 使用angular4和asp.net core 2 web api做个练习项目(二), 这部分都是angular
- 数据库 105道题目整理与吐血总结
- 使用angular4和asp.net core 2 web api做个练习项目(一)
- =.=
- JavaScript经典面试题之for循环click
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- CentOS7 nginx安装并负载mysql
- CentOS7 zabbix安装并实现其它服务器服务监控报警与自动恢复
- CentOS7 Zookeeper安装
- 【STM32F429开发板用户手册】第38章 STM32F429的FMC总线应用之是32路高速IO扩展
- 【STM32F429开发板用户手册】第39章 STM32F429的FMC总线应用之SDRAM
- react项目搭建
- 深入理解Java泛型(三)-泛型擦除及其相关内容
- webpack实战——预处理器(loader)【下篇】
- JAVA位运算等运算符总结
- 算法实现,用机器学习模拟一个opencv的边缘识别算法
- 开源公共组件仓库的更新日志应该如何写
- 判断ABAP代码是否处于update模式下运行的工具类
- SAP CRM WebClient UI异常的持久化机制
- 在ABAP Webdynpro里显示PDF的一种办法
- ABAP Webdynpro Interface View的用法