HDU1506 Largest Rectangle in a Histogram(水DP)

Arduino、ESP32驱动SFA40甲醛传感器(气体传感器篇) SFA40甲醛传感器是一款基于盛思锐电化学原理的专业HCHO检测模块,具备卓越的抗酒精干扰能力(乙醇交叉敏感度<0.3%)、高达±20ppb的检测精度及0~1000ppb的宽量程。该传感器内置SHT4X温湿度传感器进行自动补偿,确保数据的长期稳定性;其小尺寸、低功耗的特性,可快速集成至智能家居、空气净化器、物联网环境监测等系统中,实现对甲醛浓度的精准、可靠监测。 阅读详情

Largest Rectangle in a Histogram

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16166 Accepted Submission(s): 4747

Problem Description
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows the histogram that consists of rectangles with the heights 2, 1, 4, 5, 1, 3, 3, measured in units where 1 is the width of the rectangles:

Usually, histograms are used to represent discrete distributions, e.g., the frequencies of characters in texts. Note that the order of the rectangles, i.e., their heights, is important. Calculate the area of the largest rectangle in a histogram that is aligned at the common base line, too. The figure on the right shows the largest aligned rectangle for the depicted histogram.

Input
The input contains several test cases. Each test case describes a histogram and starts with an integer n, denoting the number of rectangles it is composed of. You may assume that 1 <= n <= 100000. Then follow n integers h1, …, hn, where 0 <= hi <= 1000000000. These numbers denote the heights of the rectangles of the histogram in left-to-right order. The width of each rectangle is 1. A zero follows the input for the last test case.

Output
For each test case output on a single line the area of the largest rectangle in the specified histogram. Remember that this rectangle must be aligned at the common base line.

Sample Input
7 2 1 4 5 1 3 3
4 1000 1000 1000 1000
0

Sample Output
8
4000

Source
University of Ulm Local Contest 2003

Recommend
LL | We have carefully selected several similar problems for you: 1505 1069 1087 1058 1203

注意一下结果会超过int用long long存,维护l和r数组,l[i]存储的是i位置方块左边最后一个高度大于等于它的方块位置,同理r存的是右边的位置。用dp维护一下就阔以了。

#include "cstring"
#include "cstdio"
#include "iostream"
#include "string.h"
using namespace std;
long long a[100005],l[100005],r[100005];
int main()
{
    int n;
    while(scanf("%d",&n)&&n!=0)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            l[i]=i;
            r[i]=i;
        }
        memset(l,0,sizeof(l));
        memset(r,0,sizeof(r));
        l[1]=1;
        r[n]=n;
        for(int i=2;i<=n;i++)
        {
            long long t=i;
            while(t>1&&a[i]<=a[t-1])
                t=l[t-1];
            l[i]=t;
        }
        for(int i=n;i>=1;i--)
        {
            long long t=i;
            while(t<n&&a[i]<=a[t+1])
                t=r[t+1];
            r[i]=t;
        }
        long long ans=0;
        for(int i=1;i<=n;i++)
        {
            long long now;
            now=(r[i]-l[i]+1)*a[i];
            if(ans<now)
                ans=now;
        }
        printf("%lld\n",ans);
    }

}
【STK】手把手教你利用STK进行关联分析仿真01-STK/CAT模块介绍 今天主要介绍接近分析工具CAT。 阅读详情

相关推荐

一文告诉你:如何在trae中编译运行STM32程序,并让AI帮你修改代码

本文详细介绍了如何将STM32程序从Keil迁移到国产免费工具Trae,并利用AI进行代码修改的全过程。

水滴爬呀爬 4964

HDU 1506 Largest Rectangle in a Histogram(DP)

可以发现 当第i-1个比第i个高的时候 比第i-1个高的所有也一定比第i个高 于是可以用到动态规划的思想 令left[i]表示包括i在内比i高的连续序列中最左边一个的编号 right[i]为最右边一个的编号 那么有 当h[left[i]-1]>=h[i]]时 left[i]=left[left[i]-1] 从前往后可以递推出left[i] 同理 当h[right[i]+1]>=h[i]]时 right[i]=right[right[i]+1] 从后往前可递推

Good morning,good afternoon and good night 1843

手把手教你用Matlab为PMSM电流环设计2P2Z补偿器(附与PI对比)

本文详细介绍了如何使用Matlab的controlSystemDesigner工具为永磁同步电机(PMSM)电流环设计2P2Z补偿器,并与传统PI控制器进行性能对比。通过频域分析和时域仿真,展示了2P2Z补偿器在提升带宽、减少超调等方面的优势,为高性能伺服驱动和精密运动控制提供了实用解决方案。

weixin_42551227的博客 388

hdu1506 Largest Rectangle in a Histogram

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6301    Accepted Submission(s): 1803 Problem Descriptio

Shirley 3114

Qt上位机实战:5步搞定STM32 IAP固件升级(附拖拽文件处理技巧)

本文详细介绍了如何使用Qt开发STM32 IAP固件升级上位机。通过五个核心步骤,包括理解IAP机制、搭建Qt环境、实现拖拽文件加载、封装串口通信以及设计可靠通信协议,帮助开发者快速构建一个稳定、易用且支持图形化操作的固件升级工具,显著提升嵌入式产品开发与维护效率。

ss78901的博客 1093

SIwave仿真手册——信号完整性仿真之S参数的提取(二)

上一篇简单了讲述了软件的各个操作界面,本次博客更新关于的仿真,因为第二章完整的内容比较多,所以分成好几篇博客进行分享。

luohuo9844的博客 1万+

【HDU 1506】Largest Rectangle in a Histogram(DP)

Problem DescriptionA histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure

Ice_Confuse 546

2019年上交电院计算机直博保研经历

本人选报的是上交六月一日在武汉举办的直博选拔,五月三十一日到达酒店,地点在武汉大学旁边(PS:上交是不管住宿、来回车票的,~划重点~包括夏令营),入住后当然是紧张的准备英语面试等等内容了,当天我是排在了下午面试,感觉还很好,上午可以多睡一会,最好能够去踩踩点上午,然后下午面试一定要早去,说是一点开始,但是老师十二点半就开始让学生进去了,有一个同学排在第二个,但是当时叫到他时还不到一点,没到,最后据...

LifeMaker的博客 4908

HDU1506 POJ2559 Largest Rectangle in a Histogram【单调堆栈】

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31315 Accepted Submission(s): 10156 Problem Description A h...

海岛Blog 561

提高RFID检测距离以及检测速度的方法总结

摘要:提高RFID检测距离需优化阅读器功率、标签灵敏度、天线设计及频段选择,同时减少环境干扰;提升检测速度则需改进防碰撞算法、增强并行处理能力、精简数据传输。实际应用需平衡两者关系,如物流仓储采用UHF频段、高增益天线和动态Q算法实现远距离高速读取,ETC系统则通过微波频段和高速调制实现超远距离快速识别。不同场景需针对性优化硬件配置和系统参数。

start_up_go的博客 295

超分辨率重建:ESPCN与SRGAN技术对比

超分辨率重建:ESPCN与SRGAN技术对比​ 人工智能,计算机视觉,大模型,AI,超分辨率重建是一种通过技术手段,将低分辨率图像转换为高分辨率图像的过程。它的目的是恢复低分辨率图像中丢失的细节信息,使图像具有更高的清晰度和视觉质量。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 7万+

HDU 1506 Largest Rectangle in a Histogram(DP)

http://acm.hdu.edu.cn/showproblem.php?pid=1506 Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths b

Ever_glow的博客 575

EtherCAT主站教程3--适配伺服驱动器(模式配置)

目前通用的伺服驱动器的位置模式、速度模式以及其他模式是伺服系统中常见的控制模式,切换这些模式通常需要根据具体的伺服驱动器型号和控制协议(如EtherCAT、CANopen、Modbus等)进行配置。以下是这些模式的概述及切换方法的一般性指导:协议规范中,一共有以下几种模式:其中模式1、3、6对于比较常用,也更容易上手。

weixin_52626887的博客 798

HDU1506 Largest Rectangle in a Histogram

Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the

华章 514

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDU - 1506 Largest Rectangle in a Histogram(DP)

 A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows...

Yi_Qing_Z的博客 252

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

HDU 1506 Largest Rectangle in a Histogram(dp)

题目链接:HDU 1506 Largest Rectangle in a Histogram 对于每一块木板,Area=height[i]*(j-k+1) 设其中任一块x, j=height[i]; 找j,k成为关键。 利用动态规划,如果它左边高度大于等于它本身,那么它左边的左边界一定满足这个性质,再从这个边界的左边迭代下去。左边界迭代完再迭代右边界。 在杭电提交了好多次都是TLE,

fobdddf的专栏 502

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

[HDU1506]Largest Rectangle in a Histogram[dp]

题目链接:[HDU1506]Largest Rectangle in a Histogram[dp] 题意分析:给出多个矩形条,高度随机(0 解题思路:对于每一块木板,我们可以将他向左右扩散,扩散规则为:左右大于我,我就往那边走。l[i], r[i]分别用于记录第i个板能扩散到的最左边和最右边, 于是有:面积 = h[i] * (r[i] - l[i] + 1); O(n)遍历面积求出最大

闲停 438

hdu 1506 Largest Rectangle in a Histogram (dp思想)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1506 Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14321

theArcticOcean 715

HDU 1506 Largest Rectangle in a Histogram

传送门 直方图dp。 可以借鉴最大连续子序列的思想,可以想到最后答案的形状一定是某个完整的柱形以自己完整的高度同时往左右扩散,扩散到什么地步呢?往左扩散到第一个小于自己高度的地方(从右往左数,不包括),往右扩散到第一个小于自己高度的地方(从左往右数,不包括)。也就是说,中间这个完整的柱形一定是整个矩形的最低点(木板效应)。 所以这N个柱形,每一个柱形都对应一个这样的基于自身的最大矩形。那么最终答案...

Crossing over 233

HDU 1506 Largest Rectangle in a Histogram

A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows ...

~ 382

hdu 1506 Largest Rectangle in a Histogram (DP)

Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12947    Accepted Submission(s): 3653 Problem Des

ysCover 559

Largest Rectangle in a Histogram HDU - 1506

A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows ...

Qtt110的博客 231

HDU 1506 Largest Rectangle in a Histogram(dp)

Largest Rectangle in a HistogramTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20784    Accepted Submission(s): 6338Problem DescriptionA histog...

BBHHTT的博客 213

【DP+双向链表】HDU 1506 Largest Rectangle in a Histogram题解

Link Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the ...

EPSILON的博客 162
上一篇: POJ1631(裸LIS)
下一篇: HDU2089 不要62(数位DP 两种姿势)
MrBlankIsAwesome
博客等级 码龄11年 4粉丝 196原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值