【DP】【单调栈】question 题解
来源:互联网 发布:java 调用rest接口 编辑:程序博客网 时间:2024/06/04 19:15
给一个01矩阵,求1覆盖的最大矩形面积。
统计每一个位置高度,单调栈维护,顺着跑一遍。
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <set>#include <queue>#include <algorithm>#include <vector>#include <cstdlib>#include <cmath>#include <ctime>#include <stack>#define INF 2147483647#define LL long long#define clr(x) memset(x, 0, sizeof x)#define digit (ch < '0' || ch > '9')using namespace std;template <class T> inline void read(T &x) { int flag = 1; x = 0; register char ch = getchar(); while( digit) { if(ch == '-') flag = -1; ch = getchar(); } while(!digit) { x = (x<<1)+(x<<3)+ch-'0'; ch = getchar(); } x *= flag;}const int maxn = 1005;int n,m,ans,st[maxn],ls[maxn],mp[maxn][maxn],up[maxn][maxn];int main() { freopen("question.in","r",stdin); freopen("question.out","w",stdout); read(n); read(m); for(register int i = 1; i <= n; i++) for(register int j = 1; j <= m; j++) { read(mp[i][j]); if(mp[i][j]) up[i][j] = up[i-1][j]+1; } for(register int i = 1; i <= n; i++) { int tp = 0; for(register int j = 1; j <= m; j++) if(up[i][j] >= st[tp]) st[++tp] = up[i][j], ls[tp] = 1; else { int len = 0; while(tp && st[tp] > up[i][j]) len += ls[tp], ans = max(ans, len*st[tp--]); st[++tp] = up[i][j], ls[tp] = len+1; } int len = 0; while(tp) len += ls[tp], ans = max(ans, st[tp--]*len); } cout << ans << endl; return 0;}
阅读全文
0 0
- 【DP】【单调栈】question 题解
- NOIP模拟dp专题 Question 单调栈
- question (单调栈)
- 单调栈练习题题解
- Hdu 3401 题解 单调队列优化DP
- 【DP】【单调队列】17.6.3 上网 题解
- 【DP】【单调队列】17.6.4 假期 题解
- poj3250翻译+题解(单调栈)
- dp/单调栈
- 【BZOJ】【P3831】【Poi2014】【Little Bird】【题解】【单调队列+DP】
- Hdu3401 Trade(dp 单调队列优化)最详细题解
- 【DP】【斜率优化】【单调队列优化】Gift 题解
- poj 3494 dp+单调栈
- HDU 1506-单调栈-DP
- poj 2796 Feel Good 单调栈题解
- POJ2082 Terrible Sets [DP 单调栈]
- hdu_4362 Dragon Ball (DP+单调栈)
- POJ 2796 Feel Good -- 单调栈,DP
- poj2425 博弈论 有向图
- 堆排序
- Android调用Linux命令修改文件权限的两种实现方式
- SVM关于Platt文章中SMO求解参数的具体推导过程
- vi下调整缩进长度
- 【DP】【单调栈】question 题解
- 树选中节点事件
- js基础数组方法
- 利用Java反射实现插件框架
- David Silver强化学习课程笔记(一)
- xenomai-ipipe机制简述
- HDU5950(矩阵快速幂)
- 缺失值的处理方法
- UVa 11090