题目给一个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. FineUI第二天

    原博文http://www.cnblogs.com/sanshi/archive/2012/02/12/2347789.html 1.首先复制extJS的文件夹到根目录. 2.引用程序集 3.配置配置 ...

  2. [BZOJ2959]长跑——新技能:LCT+缩圈

    [BZOJ2959]长跑 试题描述 某校开展了同学们喜闻乐见的阳光长跑活动.为了能“为祖国健康工作五十年”,同学们纷纷离开寝室,离开教室,离开实验室,到操场参加3000米长跑运动.一时间操场上熙熙攘攘 ...

  3. Leetcode 之Populating Next Right Pointers in Each Node II(51)

    void connect(TreeLinkNode *root) { while (root) { //每一层循环时重新初始化 TreeLinkNode *prev = nullptr; TreeLi ...

  4. 纯Java获得本地MAC地址

    import java.net.*; public class Ipconfig{      public static void main(String[] arguments) throws Ex ...

  5. poj1753枚举

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 33670   Accepted: 14713 Descr ...

  6. hdparm测试硬盘性能

    <1>Centos安装hdparm测试硬盘性能 一.安装hdparm yum install hdparm -y Linux学习,http:// linux.it.net.cn 二.评估读 ...

  7. HDU 5795 A Simple Nim (博弈) ---2016杭电多校联合第六场

    A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. [Android Pro] 监听WIFI 打开广播

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-perm ...

  9. PA

    [题目描述] 汉诺塔升级了:现在我们有?个圆盘和?个柱子,每个圆盘大小都不一样, 大的圆盘不能放在小的圆盘上面,?个柱子从左到右排成一排.每次你可以将一 个柱子上的最上面的圆盘移动到右边或者左边的柱子 ...

  10. Hadoop 中文编码相关问题 -- mapreduce程序处理GBK编码数据并输出GBK编码数据(转)

    hadoop的hdfs文件系统中,默认的是utf-8, 故你上传的文件是要设置成utf-8.当输入的是gbk,有该如何? 输入是GBK文件, 输出也是 GBK 文件的示例代码: Hadoop处理GBK ...