题目

分析

毫无疑问 \(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】遥远的金字塔的更多相关文章

  1. JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠

    JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...

  2. [JZOJ 100026] [NOIP2017提高A组模拟7.7] 图 解题报告 (倍增)

    题目链接: http://172.16.0.132/senior/#main/show/100026 题目: 有一个$n$个点$n$条边的有向图,每条边为$<i,f(i),w(i)>$,意 ...

  3. 【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 ...

  4. JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团

    100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms  Memory Limits: 131072 KB  Detailed Limits   Got ...

  5. JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线

    5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...

  6. JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器

    5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...

  7. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  8. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  9. 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 ...

  10. 【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 ...

随机推荐

  1. BrokenPipeError错误和subprocess.run()超时参数在Windows上无效

    1.问题的发现   今天,一个在windows上运行良好的python脚本放到linux下报错,提示错误 BrokenPipeError: [Errno 32]Broken pipe.经调查是subp ...

  2. 私藏!资深数据专家SQL效率优化技巧 ⛵

    作者:韩信子@ShowMeAI 数据分析实战系列:https://www.showmeai.tech/tutorials/40 本文地址:https://www.showmeai.tech/artic ...

  3. TornadoFx的TableView组件使用

    原文: TornadoFx的TableView组件使用 - Stars-One的杂货小窝 最近慢慢地接触了JavaFx中的TableView的使用,记下笔记总结 使用 1.基本使用 TornadoFx ...

  4. O-MVLL代码混淆方式

    在介绍O-MVLL之前,首先介绍什么是代码混淆以及基于LLVM的代码混淆,O-MVLL项目正是基于此而开发来的. 有关O-MVLL的概括介绍以及安装和基本使用方式,可参见另一篇随笔 https://w ...

  5. 浅谈字节码增强技术系列2-Asm与Cglib

    作者:董子龙 前言 记得那是2022年秋天的第一场雨,比2021年来的稍晚一些,在那个秋雨朦胧的下午,正在工位上奋笔疾书的我突然听到了前面波哥对着手机听筒说出来的"温柔"的话语:说 ...

  6. ArcObjects SDK开发 016 在ArcMap中使用Toolbox

    1.如何找到ToolBox 通过Geoprocessing菜单上的ArcToolbox菜单项,可以打开ArcToolbox面板. 工具栏上也有一个ArcToolbox的按钮,点击该按钮也可以打开. 通 ...

  7. 第三模块的下载、requests模块、openpyxl模块

    目录 第三方模块的下载安装 下载第三模块的方式 针对下载第三模块时可能会出现的问题 网络爬虫模块之requests模块 自动化办公领域之openpyxl模块 第三方模块的下载安装 第三方模块:别人写的 ...

  8. vue中单独封装elementui中的Dialog弹框组件

    一.在components文件中新建 弹框组件 <template> <div> <el-dialog title="提示" :visible.syn ...

  9. [编程基础] Python格式化字符串常量f-string总结

    Python格式化字符串常量f-string总结 本文主要总结在Python中如何使用格式化字符串常量f-string(Formatted string literals).在 Python 程序中, ...

  10. Python自动化操作sqlite数据库

    你好,我是悦创. 原文首发:https://bornforthis.cn/column/pyauto/ 1. 什么是数据库 数据库是"按照数据结构来组织.存储和管理数据的仓库",是 ...