题目给一个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. Junit4.x扩展:运行指定方法

    相信很多道友搞开发的一般都会用到Junit单元测试工具,不知道大家有没有遇到一个这样的问题: 有的单元测试用例有很多@Test方法,甚至有的方法会执行很长时间,只能空等执行.而实际上我们只需要运行其中 ...

  2. 15 条实用 Linux/Unix 磁带管理命令

    导读 磁带设备应只用于定期的文件归档或将数据从一台服务器传送至另一台.通常磁带设备与 Unix 机器连接,用 mt 或 mtx 控制.强烈建议您将所有的数据同时备份到磁盘(也许是云中)和磁带设备中. ...

  3. 在iOS7中修改状态栏字体的颜色

    http://www.2cto.com/kf/201408/324442.html 默认状态栏的字体为黑色:UIStatusBarStyleDefault 状态栏的字体为白色:UIStatusBarS ...

  4. HDOJ 1106

    #include<iostream> #include<algorithm> #include<string.h> #include<stdlib.h> ...

  5. PE刷题记录

    PE刷题记录 PE60 / 20%dif 这道题比较坑爹. 所有可以相连的素数可以构成一张图,建出这张图,在其中找它的大小为5的团.注意上界的估算,大概在1W以内.1W内有1229个素数,处理出这些素 ...

  6. LVS-三种负载均衡方式比较

    1.什么是LVS? 首 先简单介绍一下LVS (Linux Virtual Server)到底是什么东西,其实它是一种集群(Cluster)技术,采用IP负载均衡技术和 基于内容请求分发技术.调度器具 ...

  7. 【Python】Django 如何直接返回404 被 curl,wget 捕获到

    代码示例: from django.http import Http404, HttpResponseNotFound #raise Http404(filename) return HttpResp ...

  8. Longest Common Subsequence & Substring & prefix

    Given two strings, find the longest common subsequence (LCS). Your code should return the length of  ...

  9. Linux系统Shutdown命令定时关机详解

    转自:http://www.bootf.com/490.html Linux系统下的shutdown命令用于安全的关闭/重启计算机,它不仅可以方便的实现定时关机,还可以由用户决定关机时的相关参数.在执 ...

  10. Delphi经验总结(1)

    先人的DELPHI基础开发技巧 ◇[DELPHI]网络邻居复制文件 uses shellapi; copyfile(pchar('newfile.txt'),pchar('//computername ...