您的位置:首页 > 移动开发

HDU 2830 Matrix Swapping II(dp最大子矩阵和)

2016-09-14 18:09 483 查看
//
//  main.cpp
//  Richard
//
//  Created by 邵金杰 on 16/9/14.
//  Copyright © 2016年 邵金杰. All rights reserved.
//

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1000+10;
int h[maxn][maxn],p[maxn];
char map[maxn][maxn];
int n,m;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int MAX=-1;
memset(h,0,sizeof(h));
for(int i=1;i<=n;i++)
scanf("%s",map[i]+1);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(map[i][j]=='1') h[i][j]=1+h[i-1][j];
}
memcpy(p+1,h[i]+1,sizeof(int)*m);
sort(p+1,p+m+1);
for(int j=1;j<=m;j++)
MAX=max(MAX,(m-j+1)*p[j]);
}
printf("%d\n",MAX);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: