poj 3494

来源:互联网 发布:什么相机软件最好 编辑:程序博客网 时间:2024/06/18 15:12

#include <iostream>#include <fstream>#include <cstring>using namespace std;int M,N;int map[2000][2000];int a[2000];int b[2000];int res;void init(){memset(map, 0, sizeof(map) );memset(a, 0, sizeof(a) );memset(b, 0, sizeof(b) );res = 0;int i,j,t;for(i = 0; i < M; ++i){for(j = 0; j < N; ++j){scanf("%d",&t);map[i][j] = t;}}}int getOne(int n){int i,max = 0, finish = 0;for(i=0; i<N; ++i){if(a[i] == 1)++max;else{if(finish < max ) finish = max;max = 0;}}if(finish < max ) finish = max;return finish * n;}void putA(int nowLine){int i;for(i=0; i<N; ++i){a[i] = map[nowLine][i];}}void putB(int nowLine){int i;for(i=0; i<N; ++i){b[i] = map[nowLine][i];}}void aYUb(){int i;for(i=0; i<N; ++i){a[i] = a[i]&b[i];}}void nextLine(int nowLine){//printf("LINE : %d\n",nowLine);putA(nowLine);int n = 1,max;while(n <= M){max = getOne(n);//printf("max = %4d%4d\n",max, n);if(max == 0)return ;if(res < max) res = max;putB(nowLine + n);aYUb();++n;}}int main(){//freopen("a.txt","r",stdin);//freopen("b.txt","w",stdout);int j=0,i=0;while(scanf("%d%d",&M, &N)==2){init();for(i=0; i<M; ++i){nextLine(i);}printf("%d\n", res);}}

超时了,是因为,MN,范围太大了,有2000位,没有一个语言的一个类型可以分配500个字节给int,只有退而求其次,用字符串(本来想用一个整数的),

模似与运算。因此,就超时了;