hdu2830

来源:互联网 发布:visual mac 编辑:程序博客网 时间:2024/06/06 08:15
/*
分析:
    DP。
    记不清有多久没写过DP了-、-III,还是和以前一样觉得DP很
有意思,DP的状态递推思想真的很犀利~
    由于不管怎么换,锁定一个列,那么该列的元素是一直不变
的,多以可以针对这个,用dp[i]表示该被锁定的列中,连续到第
i行有几个1。
    打出上面的dp表,由于列可以无限交换,所以将这一行的dp从
大到小排列后,temp1=dp[1]*1,temp2=dp[2],*2,temp3=dp[3]*3,
temp4=dp[4]*4,……,那么max(temp)就是这一行中的ans。对所有行
进行这个,就可以求出整个图的ANS。


                                                      2012-11-08


*/










#include"stdio.h"#include"string.h"#include"stdlib.h"#define N 1011char map[N][N];int dp[N][N];int cmp(const void *a,const void *b){return *(int *)b-*(int *)a;}int main(){int n,m;int i,l;int temp;int ans;while(scanf("%d%d",&n,&m)!=-1){for(i=0;i<n;i++)scanf("%s",map[i]);for(l=0;l<m;l++)dp[0][l]=map[0][l]-'0';for(l=0;l<m;l++)for(i=1;i<n;i++){if(map[i][l]=='0')dp[i][l]=0;elsedp[i][l]=dp[i-1][l]+1;}ans=0;for(i=0;i<n;i++){qsort(dp[i],m,sizeof(dp[i][0]),cmp);for(l=0;l<m;l++){temp=dp[i][l]*(l+1);ans=ans>temp?ans:temp;}}printf("%d\n",ans);}return 0;}