51 nod 1158 全是1的最大子矩阵
可以把问题转化成poj2559的这种问题,然后按照每行去计算。
推荐一篇blog
链接说明
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef double dl;
const int N = 1e5+7;
const int M = 1e9+7;
const int INF = 0x7fffffff;
int n,m;
int h[N];
int a[N];
stack<int> st;
void solve()
{
scanf("%d%d",&n,&m);
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int x;
scanf("%d",&x);
if(x==1) h[j]=h[j]+1;
else h[j]=0;
a[j]=h[j];
}
a[m+1]=-1;
for(int j=1;j<=m+1;j++)
{
if(st.empty()||a[j]>=a[st.top()])
{
st.push(j);
}
else
{
int top;
while(!st.empty()&&a[j]<a[st.top()])
{
top=st.top();
ans=max(ans,((j-top)*a[top]));
st.pop();
}
st.push(top);
a[top]=a[j];
}
}
}
printf("%d\n",ans);
}
int main()
{
solve();
}