【HDOJ】1506 Largest Rectangle in a Histogram
2024-08-27 05:18:00
Twitter还是Amazon拿这个题目当过面试题。DP区间求面积。
/* 1506 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 100005
#define INF 999999 int l[MAXN], r[MAXN];
__int64 a[MAXN]; __int64 max(__int64 a, __int64 b) {
return a>b ? a:b;
} int main() {
int n;
int i, j, k;
__int64 ans; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d",&n)!=EOF && n) {
for (i=; i<=n; ++i)
scanf("%I64d", &a[i]);
a[] = a[n+] = -INF;
l[] = ;
for (i=; i<=n; ++i) {
if (a[i-] < a[i]) {
l[i] = i;
} else {
j = i;
while (j--) {
if (a[j] < a[i]) {
l[i] = j+;
break;
} else {
j = l[j];
}
}
}
}
r[n+] = n+;
for (i=n; i>; --i) {
if (a[i+] < a[i]) {
r[i] = i;
} else {
j = i;
while (j++ <= n) {
if (a[j] < a[i]) {
r[i] = j - ;
break;
} else {
j = r[j];
}
}
}
} ans = -INF;
for (i=; i<=n; ++i) {
ans = max(ans, a[i]*(r[i]-l[i]+));
}
printf("%I64d\n", ans);
} return ;
}
最新文章
- 前端ps常用的小技巧
- markdown语法书
- js script中引用其他script
- http学习笔记(四)——HTTP报文
- web开发workflow
- 一个介绍webrtc的国外网址
- Lambda(2)
- Linux中ifreq 结构体分析和使用 及其在项目中的简单应用
- SQL 添加字段和默认值脚本
- html动态编辑框
- 快速构建Windows 8风格应用2-创建调试应用
- OpenCV探索之路(二十八):Bag of Features(BoF)图像分类实践
- poj1699
- 如何让html中的td文字只显示部分
- python就业班-淘宝-目录.txt
- unity3d-绘制贴图
- PIVOT函数与UNPIVOT函数的运用
- Linux嵌入式内核模块程序设计
- Java50道经典习题-程序6 求最大公约数及最小公倍数
- ORA-10485: Real-Time Query cannot be enabled while applying migration redo