题意: 给定一个N*M的01矩阵,在可以交换列的情况下,求出最
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
大的全1的子矩阵。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
转化成列的高度值,排序后有 ans=max(ans,h[i]*i)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=4002;
int sum[maxn],h[maxn],n,m,ans;
char ch[maxn];
int cmp(int a,int b)
{
return a>b?1:0;
}
int main()
{
// freopen("//media/学习/ACM/input.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
int i,j;
memset(h,0,sizeof(int)*(m+2));
for(ans=0,i=0;i<n;i++)
{
scanf("%s",ch);
for(j=0;j<m;j++)
{
if(ch[j]=='1')h[j]++;
else h[j]=0;
sum[j]=h[j];
}
sort(sum,sum+m,cmp);
for(j=0;j<m;j++)
{
if(ans<sum[j]*(j+1))ans=sum[j]*(j+1);
}
}
printf("%d\n",ans);
}
return 0;
}