【题目链接】 http://poj.org/problem?id=3494

【题目大意】

  在01矩阵中求最大全1子矩形

【题解】

  在处理每个点的时候,继承上一个点等高度下的左右最大扩展,
  计算在该层的左右最大扩展,然后对于每个点更新答案即可。

【代码】

#include <cstdio>
#include <cstring>
using namespace std;
const int N=2010;
int i,j,n,m,ans,l[N],r[N],h[N],lmax,rmax,a[N][N];
int main(){
while(~scanf("%d%d",&n,&m)){
ans=0;
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&a[i][j]);
for(int i=1;i<=m;i++)l[i]=1,r[i]=m;
for(int i=1;i<=n;i++){
for(lmax=j=1;j<=m;j++)if(a[i][j]){
h[j]++;
if(lmax>l[j])l[j]=lmax;
}else h[j]=0,l[j]=1,r[j]=m,lmax=j+1;
for(rmax=j=m;j;j--)if(a[i][j]){
if(rmax<r[j])r[j]=rmax;
if((r[j]-l[j]+1)*h[j]>ans)ans=(r[j]-l[j]+1)*h[j];
}else rmax=j-1;
}printf("%d\n",ans);
}return 0;
}

POJ 3494 Largest Submatrix of All 1’s(最大子图形)的更多相关文章

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

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

  3. POJ 3494 Largest Submatrix of All 1’s(最大全1子矩阵)

    题目链接:http://poj.org/problem?id=3494 题意:给出一个01的矩阵,找出一个面积最大的全1矩阵. 思路:用h[i][j]表示从位置(i,j)向上连续1的最大长度.之后枚举 ...

  4. POJ 3494 Largest Submatrix of All 1’s

    POJ 2796 Feel Good HDU 1506 Largest Rectangle in a Histogram 和这两题一样的方法. #include<cstdio> #incl ...

  5. [POJ2559&POJ3494] Largest Rectangle in a Histogram&Largest Submatrix of All 1’s 「单调栈」

    Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题 ...

  6. POJ-3494 Largest Submatrix of All 1’s (单调栈)

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

  7. 第一周任务Largest Submatrix of All 1’s

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

  8. Largest Submatrix(动态规划)

    Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. hdu 2870 Largest Submatrix(平面直方图的最大面积 变形)

    Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change ...

随机推荐

  1. bzoj 4555 [Tjoi2016&Heoi2016]求和 NTT 第二类斯特林数 等比数列求和优化

    [Tjoi2016&Heoi2016]求和 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 679  Solved: 534[Submit][S ...

  2. Install the Active Directory Administration Tools on Windows Server

    安装 Active Directory 管理工具 To manage your directory from an EC2 Windows instance, you need to install ...

  3. 使用state模块部署lamp架构

    install_httpd: pkg.installed: - name: httpd httpd_running: service.running: - name: httpd - enable: ...

  4. 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

    [题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...

  5. 玩转Metasploit系列(第二集)

    在上一节的内容中,大家了解了Metasploit的结构.这一节我们主要介绍的是msfconsole的理论. msfconsole理论 在MSF里面msfconsole可以说是最流行的一个接口程序.很多 ...

  6. Swift 闭包(六)

    http://blog.csdn.net/huangchentao/article/details/32714185 闭包 Closures 1.闭包表达式 闭包表达式是一种利用简单语法构建内联包的方 ...

  7. 一.Select 函数详细介绍【转】

    转自:http://www.cnblogs.com/hjslovewcl/archive/2011/03/16/2314330.html Select在Socket编程中还是比较重要的,可是对于初学S ...

  8. mysql约束与索引的区别

    一:约束 作用:是为了保证数据的完整性而实现的一套机制,它具体的根据各个不同的数据库的实现而有不同的工具(约束): 这里主要讲解mysql的约束: 1.非空约束:not null; 指示某列不能存储 ...

  9. JavaScript秘密花园

    译文地址 bonsaiden.github.io/JavaScript-Garden/zh/#intro.authors 之前被人问到JS一些概念性的东西,感觉很模糊,可能层次比较浅,偏理论的东西实践 ...

  10. KDJ金叉测试

    # -*- coding: utf-8 -*- import os import pandas as pd # ========== 遍历数据文件夹中所有股票文件的文件名,得到股票代码列表stock_ ...