额,今天的意外收获就是单调栈。
还有个单调队列,得看看了:
#include<stdio.h>
#include<string.h>
#include<math.h>
int n,m;
int a[2005],stack[2005],pos[2005],ans;
int GetAns()
{
int i,top;
top=0;
stack[0]=pos[0]=0;
for (i=1; i<=n ; i++ )
{
while (top&&a[i]<=stack[top])
{
if (ans<(i-1-pos[top-1])*stack[top])
ans=(i-1-pos[top-1])*stack[top];
top--;
}
top++;
stack[top]=a[i];
pos[top]=i;
}
while (top)
{
if (ans<(n-pos[top-1])*stack[top])
ans=(n-pos[top-1])*stack[top];
top--;
}
return 0;
}
int main()
{
int i,j,x;
while (scanf("%d%d",&m,&n)==2)
{
memset(a,0,sizeof(a));
ans=0;
for (i=1; i<=m ; i++ )
{
for (j=1; j<=n ; j++ )
{
scanf("%d",&x);
if (x)
a[j]++;
else
a[j]=0;
}
GetAns();
}
printf("%d\n",ans);
}
return 0;
}
sdu的段神说的poj3050该看看了,