POJ3493 Largest Submatrix of All 1’s(单调栈)
题目给一个01矩阵,求最大的1子矩阵。
先用dp预处理出每一行的每一列的1能向上按连续的1延伸多少,然后枚举每一行作为子矩阵的底,那样对于每一行的答案就是POJ2559这个经典问题了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 2222
int stack[MAXN],top,l[MAXN],r[MAXN];
int calc(int *a,int n){
a[++n]=-; top=;
for(int i=; i<=n; ++i){
l[i]=r[i]=i;
while(top && a[stack[top]]>a[i]){
r[stack[top]]=i-;
l[i]=l[stack[top]];
--top;
}
if(top && a[stack[top]]==a[i]) l[i]=l[stack[top]];
stack[++top]=i;
}
int res=;
for(int i=; i<n; ++i){
res=max(res,a[i]*(r[i]-l[i]+));
}
return res;
}
int d[MAXN][MAXN];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=; i<=n; ++i){
for(int j=; j<=m; ++j) scanf("%d",&d[i][j]);
}
for(int i=; i<=n; ++i){
for(int j=; j<=m; ++j){
if(d[i][j]) d[i][j]=d[i-][j]+;
}
}
int res=;
for(int i=; i<=n; ++i){
res=max(res,calc(&d[i][],m));
}
printf("%d\n",res);
}
return ;
}
POJ3493 Largest Submatrix of All 1’s(单调栈)的更多相关文章
- POJ - 3494 Largest Submatrix of All 1’s 单调栈求最大子矩阵
Largest Submatrix of All 1’s Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is ...
- POJ 3494 Largest Submatrix of All 1’s 单调队列||单调栈
POJ 3494 Largest Submatrix of All 1’s Description Given a m-by-n (0,1)-matrix, of all its submatrice ...
- POJ3494Largest Submatrix of All 1’s[单调栈]
Largest Submatrix of All 1’s Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 5883 Ac ...
- poj 2559 Largest Rectangle in a Histogram (单调栈)
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 6 ...
- poj2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- 题解报告:poj 2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- HDU-1506 Largest Rectangle in a Histogram【单调栈】
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- Largest Rectangle in a Histogram【单调栈模板】
Largest Rectangle in a Histogram 题目链接(点击)来源poj 2559 A histogram is a polygon composed of a sequence ...
- hdu_1506:Largest Rectangle in a Histogram 【单调栈】
题目链接 对栈的一种灵活运用吧算是,希望我的注释写的足够清晰.. #include<bits/stdc++.h> using namespace std; typedef long lon ...
- ☆ [POJ2559] Largest Rectangle in a Histogram 「单调栈」
类型:单调栈 传送门:>Here< 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题思路 单调栈的经典题 显然,最终的子矩形高度一定和某一个矩形相等(反证).因此一 ...
随机推荐
- Eclipse的模板设置代码
Eclipse Java注释模板设置详解 设置注释模板的入口: Window->Preference->Java->Code Style->Code Template 然后 ...
- Apache VirtualHost配置
转载:http://www.cnblogs.com/wpjsolo/archive/2012/01/19/2327457.html 以lampp环境为例子,其他环境只是配置文件的路径不同. 先要在 ...
- 查看现有运行的linux服务器有多少内存条
i161 admin # ssh 192.168.5.209 dmidecode | grep 'Ending Address' -B1 -A2 Starting Address: 0x0000 ...
- CentOS6.5以runlevel 3开机时自动连接某无线设置示例
[参考]http://blog.csdn.net/simeone18/article/details/8580592 [方法一] 假设无线网卡代号为wlan0,无线AP的essid为:TheWiFi, ...
- 如何判断CPU字节序之[Big-endian vs Little-endian]
[本文链接] http://www.cnblogs.com/hellogiser/p/big-endian-vs-little-endian.html [Big-endian vs Little-en ...
- 56. 2种方法判断二叉树是不是平衡二叉树[is balanced tree]
[本文链接] http://www.cnblogs.com/hellogiser/p/is-balanced-tree.html [题目] 输入一棵二叉树的根结点,判断该树是不是平衡二叉树.如果某二叉 ...
- cmd的rd命令简单解析
我们知道在Windows下cmd命令行中"rd 文件夹名称"可以删除空目录,"del 文件名"可以删除文件,那么怎么删除一个非空文件夹呢,命令如下: 比如删除文 ...
- Android涉及到的设计模式
转载地址:http://blog.csdn.net/dengshengjin2234/article/details/8502097 1.适配器模式:ListView或GridView的Adapter ...
- kvm NET 和 BRIDGE
net: <interface type='network'> <mac address='52:54:00:e1:ac:43'/> <source network='d ...
- svn利用钩子post-commit自动更新到线上测试服务器(测试中未验证)
创建一个新的版本库: [root@centos03 svn]# pwd /home/svn [root@centos03 svn]# svnadmin create webtest [root@cen ...