Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest we mean that the submatrix has the most elements.

Input

The input contains multiple test cases. Each test case begins with m and n (1 ≤ m, n ≤ 2000) on line. Then come the elements of a (0,1)-matrix in row-major order on m lines each with n numbers. The input ends once EOF is met.

Output

For each test case, output one line containing the number of elements of the largest submatrix of all 1’s. If the given matrix is of all 0’s, output 0.

Sample Input

2 2
0 0
0 0
4 4
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0

Sample Output

0
4 单调栈,每一行记录个列的高度 然后每一行进行单调栈,用输入输出流还是超时得用scanf。。或者 用scanf就不错。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
using namespace std;
int n,m,d;
int mp[][];
int l[]={},r[],stack[],top,maxi,sum;
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0); while(scanf("%d%d",&n,&m)!=EOF)
{
maxi=;
for(int i=;i<=n;i++)
{
top=;
for(int j=;j<=m;j++)
{
scanf("%d",&d);
//mp[i][j]=mp[i][j-1]+d; 不对的 中间如果有0 应该中断
mp[i][j]=(d==?:(mp[i-][j]+d));
l[j]=r[j]=j;
}
for(int j=;j<=m+;j++)
{
while(top>&&mp[i][j]<=mp[i][stack[top-]])
{
r[stack[top-]]=j-;
sum=(r[stack[top-]]-l[stack[top-]]+)*mp[i][stack[top-]];
if(sum>maxi)maxi=sum;
top--;
}
l[j]=stack[top-]+;
stack[top++]=j;
}
} printf("%d\n",maxi);
}
}
/*
4 4
1 0 1 1
0 1 1 1
0 0 1 1
0 1 1 1
*/

Largest Submatrix of All 1’s的更多相关文章

  1. Largest Submatrix(动态规划)

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

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

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

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

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

  4. codeforces 407D Largest Submatrix 3

    codeforces 407D Largest Submatrix 3 题意 找出最大子矩阵,须满足矩阵内的元素互不相等. 题解 官方做法 http://codeforces.com/blog/ent ...

  5. Largest Submatrix of All 1’s(思维+单调栈)

    Given a m-by-n (0,1)-matrix, of all its submatrices of all 1's which is the largest? By largest we m ...

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

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

  8. HDU 2870 Largest Submatrix (单调栈)

    http://acm.hdu.edu.cn/showproblem.php? pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Oth ...

  9. MINSUB - Largest Submatrix

    MINSUB - Largest Submatrix no tags  You are given an matrix M (consisting of nonnegative integers) a ...

随机推荐

  1. robotframework安装与配置--学习第一天

    刚刚入职公司,之前学的是Java+selenium自动化测试,但公司要求使用robot framework,所以找了些资料学习.刚开始觉得为什么不用java.python等开发语言+selenium做 ...

  2. 滑动窗口解决Substring Search Problem

    2018-07-18 11:19:19 一.Minimum Window Substring 问题描述: 问题求解: public String minWindow(String s, String ...

  3. Asp.Net MVC中Action跳转

    首先action的跳转大致归类: 1跳转到与当前同一控制器内的action和不同控制器内的action. 2带有参数的action跳转和不带参数的action跳转. 3跳转到指定视图,不经过Contr ...

  4. .NET中使用Rabbit MQ

    1.通过Nuget 获取Rabbit MQ NET client bindings from NuGet: PM> Install-Package RabbitMQ.Client 2.发送者(生 ...

  5. nyoj1272表达式求值(递归法)

    递归写的,类似于之前的一道,但要更难一点,因为加入了'+','*'以及括号运算符,所以要考录周全: 这道题给了我很大启示,在第一道德基础上: 1!寻找括号的优先级,先找有没有不被任何括号夹住的加号,如 ...

  6. POJ-2689 Prime Distance (两重筛素数,区间平移)

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13961   Accepted: 3725 D ...

  7. failed to load response data

    当需要根据后台传回地址跳转页面时 即使使用preserve log 可以查看上一个页面获取地址请求,但是此时请求返回值为failed to load response data 当关闭页面跳转可以查看 ...

  8. 新手如何正确使用CLion之输出hello world

    以前只使用过vc6.0,在用过jetbrain的pycharm后就考虑换个c++的编译器了,第一还是考虑了vs2017但用惯了色彩鲜艳的jb产品后竟然有点不习惯vs,最后还是果断选择了jb的CLion ...

  9. OC @property @synthesize和id

    文顶顶   OC语言@property @synthesize和id OC语言@property @synthesize和id 一.@property @synthesize关键字 注意:这两个关键字 ...

  10. 线程正常终止pthread_exit,pthread_join,pthread_kill,pthread_cancel,sigwait,sigaddset

    int pthread_join(pthread_t thread, void **retval); int pthread_detach(pthread_t thread); void pthrea ...