题目给一个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(单调栈)的更多相关文章

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

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

  3. POJ3494Largest Submatrix of All 1’s[单调栈]

    Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 5883   Ac ...

  4. poj 2559 Largest Rectangle in a Histogram (单调栈)

    http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 6 ...

  5. poj2559 Largest Rectangle in a Histogram(单调栈)

    Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...

  6. 题解报告: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 ...

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

  8. Largest Rectangle in a Histogram【单调栈模板】

    Largest Rectangle in a Histogram 题目链接(点击)来源poj 2559 A histogram is a polygon composed of a sequence ...

  9. hdu_1506:Largest Rectangle in a Histogram 【单调栈】

    题目链接 对栈的一种灵活运用吧算是,希望我的注释写的足够清晰.. #include<bits/stdc++.h> using namespace std; typedef long lon ...

  10. ☆ [POJ2559] Largest Rectangle in a Histogram 「单调栈」

    类型:单调栈 传送门:>Here< 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题思路 单调栈的经典题 显然,最终的子矩形高度一定和某一个矩形相等(反证).因此一 ...

随机推荐

  1. Internet信息服务找不到

    最近我的电脑也出现了Internet信息服务找不到的情况,在网络上查了很多方法都没一个正确的,后面通过下面的方法我成功了,故此我把这个经历也分享给大家,希望能够帮到您. 控制面板里“->添加/删 ...

  2. 存在使i > j || i <= j不成立的数吗?

    存在使i > j || i <= j不成立的数吗? 咋一看有点晕!一个数既不能大于也不能小于等于另一个数?那是什么数?答案是”非数“ 例子如下:‘ if(Double.NaN>Flo ...

  3. [Effective JavaScript 笔记]第20条:使用call方法自定义接收者来调用方法

    不好的实践 函数或方法的接收者(即绑定到特殊关键字this的值)是由调用者的语法决定的.方法调用语法将方法被查找的对象绑定到this变量,(可参阅之前文章<理解函数调用.方法调用及构造函数调用之 ...

  4. linux shell 流程控制

    导读 和Java.PHP等语言不一样,linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介绍下,各个语句使 ...

  5. Unity3D占用内存太大的解决方法

    原地址:http://www.cnblogs.com/88999660/archive/2013/03/15/2961663.html 最近网友通过网站搜索Unity3D在手机及其他平台下占用内存太大 ...

  6. IOS 页面之间的跳转

    1.UINavigationController popToViewController 对应popViewControllerAnimated: 也可以使用: [self.navigationCon ...

  7. 用Python操纵MySQL

    本例用Python操纵MySQL,从指定文件读取数据,并对数据进行处理,处理之后批量插入MySQL. 贴上代码: # -*- coding: gbk -*- import re import MySQ ...

  8. 生成PHP数组文件

    1. 解释型语言的妙处之一,在于可以动态生成代码再调用执行~2. 对于数据量不大(几千条?)的(key,value),存成数组文件,执行查找操作,效率应该是好于数据库操作的:3. php的数组,是ha ...

  9. android 自定义Dialog背景透明及显示位置设置

    先贴一下显示效果图,仅作参考: 代码如下: 1.自定义Dialog public class SelectDialog extends AlertDialog{ public SelectDialog ...

  10. IP地址,子网掩码,默认网关

    IP地址: 是给每个连接在Internet上的主机分配的一个32bit地址. 地址有两部分组成,一部分为网络地址,另一部分为主机地址. IP地址分为A.B.C.D.E 5类.常用的是B和C两类. 网络 ...