您的位置:首页 > 其它

【POJ】3494 Largest Submatrix of All 1’s

2012-07-19 20:52 253 查看
#include<cstdio>
#include<algorithm>
#define MAXN 2010
using namespace std;
int a[MAXN][MAXN];
struct node
{
int w,h;
}st[MAXN];
int main()
{
node temp;
int n,m,i,j,ans,top,wide;
while(~scanf("%d%d",&n,&m))
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
}
for(i=1;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j])
a[i][j]+=a[i-1][j];
}
}
for(ans=i=0;i<n;i++)
{
top=-1;
for(j=0;j<m;j++)
{
for(wide=0;top>-1&&st[top].h>=a[i][j];top--)
{
wide+=st[top].w;
ans=max(ans,wide*st[top].h);
}
temp.w=wide+1;
temp.h=a[i][j];
st[++top]=temp;
}
for(wide=0;top>-1;top--)
{
wide+=st[top].w;
ans=max(ans,st[top].h*wide);
}
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: