JZOJ 5347. 【NOIP2017提高A组模拟9.5】遥远的金字塔
题目
分析
毫无疑问 \(dp\)
设 \(f_{i,j}\) 表示选到第 \(i\) 层,已选 \(j\) 个矩阵最大覆盖面积
那么 \(f_{i,j}=\max{f_{l,j}+w_i*(i-l)}\)
显然斜率优化
\(Code\)
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
int n , k , q[20005];
LL f[20005][105];
struct node{
int x , y , w;
}p[20005];
double slope(int j , int l , int r)
{
return 1.0 * (f[l][j] - f[r][j]) / (l - r);
}
int main()
{
freopen("pyramid.in" , "r" , stdin);
freopen("pyramid.out" , "w" , stdout);
scanf("%d%d" , &n , &k);
for(register int i = 1; i <= n; i++)
scanf("%d%d" , &p[i].x , &p[i].y) , p[i].w = p[i].y - p[i].x + 1;
int h , t;
for(register int j = 1; j <= k; j++)
{
h = t = 1;
for(register int i = 1; i <= n; i++)
{
while (h < t && slope(j - 1 , q[h + 1] , q[h]) > p[i].w) h++;
f[i][j] = f[q[h]][j - 1] + 1LL * p[i].w * (i - q[h]);
while (h <= t && slope(j - 1 , q[t] , q[t - 1]) < slope(j - 1 , i , q[t])) t--;
q[++t] = i;
}
}
LL ans = 0;
for(register int i = 1; i <= n; i++) ans = max(ans , f[i][k]);
printf("%lld" , ans);
}
JZOJ 5347. 【NOIP2017提高A组模拟9.5】遥远的金字塔的更多相关文章
- JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠
JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...
- [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)
题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...
- 【NOIP2017提高A组模拟9.7】JZOJ 计数题
[NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ...
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...
- 【NOIP2017提高A组模拟9.17】信仰是为了虚无之人
[NOIP2017提高A组模拟9.17]信仰是为了虚无之人 Description Input Output Sample Input 3 3 0 1 1 7 1 1 6 1 3 2 Sample O ...
随机推荐
- ORCL 时间
一.计算时间差 两个Date类型字段:START_DATE,END_DATE,计算这两个日期的时间差(分别以天,小时,分钟,秒,毫秒): 天: ROUND(TO_NUMBER(END_DATE - S ...
- linux内核源码下载地址
一.官网链接 https://www.kernel.org/ 二.HTTP https://www.kernel.org/pub/ 三.GIT https://git.kernel.org/ 四.镜像 ...
- 【面试题总结】JVM02:JVM参数调优、类加载机制
四.JVM参数调优 1.调优工具 (1)jvisualvm:jdk提供的性能分析工具,可以监控java进程,对dump文件分析:查看应用程序的详细信息,针对不同插件,实现监控GC过程.内存.进程.线程 ...
- bug处理记录:Error running 'WorkflowApplication': Command line is too long. Shorten command line for WorkflowApplication or also for Spring Boot default configuration?
1.报错信息 Error running 'WorkflowApplication': Command line is too long. Shorten command line for Workf ...
- Rust 学习之旅(7):Package,Crate,Module
Rust 学习之旅(7):Package,Crate,Module 这是第 7 章的读书笔记,Cargo Workspace 在第 14 章. Packages and Crates As a pro ...
- MySQL基础知识(二)-超详细 Linux安装MySQL5.7完整版教程及遇到的坑
1.简介 我们经常会在Linux上安装MySQL数据库,但是安装的时候总是会这里错,那里错,不顺利,今天整理了一下安装流程,连续安装来了两遍,没有遇到什么大错误,基本上十分钟左右可以搞定,教程如下.写 ...
- 什么是JS?JS的用途?
一.JavaScript是什么?它有什么作用? JavaScript是一种运行在客户端的脚本语言,简称JS,属于解释性语言.它是一行翻译执行完以后再进行下一行,代码不进行预编译. JavaScript ...
- ORM执行sql语句 双下划线 外键字段创建 ORM跨表查询
目录 模型层之ORM执行SQL语句 方式1一 方式二 方式三 神奇的双下划线查询 ORM外键字段的创建 1.创建基础表 2.确定外键关系 3.表的查看 数据的录入 外键字段相关操作 针对一对多 ''' ...
- Graph Neural Network——图神经网络
本文是跟着李沐老师的论文精度系列进行GNN的学习的,详细链接请见:零基础多图详解图神经网络(GNN/GCN)[论文精读] 该论文的标题为<A Gentle Introduction to Gra ...
- [seaborn] seaborn学习笔记0-seaborn学习笔记章节
seaborn学习笔记章节 seaborn是一个基于matplotlib的Python数据可视化库.seaborn是matplotlib的高级封装,可以绘制有吸引力且信息丰富的统计图形.相对于matp ...