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 mlines 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 20 00 04 40 0 0 00 1 1 00 1 1 00 0 0 0
Sample Output
04
题意:
找最大的为1的子矩阵,
一开始的错误代码:H是表示他的连续高度,L和R是左边第一个比他小的坐标和右边比他小的坐标,这个过程都是单调栈维护的,
然后暴力枚举最大的点,但是这样有错误,就是L到R这个区间内H的值不一定是相同的
错误代码:
#include#include #include #include #include #include #include
AC代码:
#include#include #include #include #include #include #include #include #include const int maxn=2e5+5;typedef long long ll;using namespace std;int H[2005];int a[2005];int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int n,m,x,top,tmp,maxnxx; stack S1; while(cin>>n>>m) { maxnxx=0; memset(H,0,sizeof(H)); for(int t=0;t =a[S1.top()]) { S1.push(j); } else { while(!S1.empty()&&a[j] maxnxx) maxnxx=tmp; } S1.push(top); a[top]=a[j]; } } } cout< <