1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#include <iostream> using namespace std; int arr[105][105]; int M,N; int Matsum(int a,int b) { int p,max_end_here=0,max_so_far=0; int Line[105]; for(int i=1;i<=N;i++) { p = 0; for(int j=a;j<=b;j++) { p+=arr[j][i]; } Line[i]=p; } max_end_here=0; max_so_far=0; for(int i=1;i<=N;i++) { max_end_here = max_end_here + Line[i]; if(max_end_here<0) max_end_here = 0; if(max_so_far<max_end_here) max_so_far = max_end_here; } return max_so_far; } int main() { int a; int mx=0,x; while(cin>>M>>N) { if(M==0 && N==0) break; for(int i=1;i<=M;i++) { for(int j=1;j<=N;j++) { cin>>a; if(a==0) arr[i][j]=1; //a = -1; if(a) arr[i][j]=-1000000;//a[i-1][j]+a; } } mx = 0; for(int i=1;i<=M;i++) { for(int j=i;j<=M;j++) { x = Matsum(i,j); if(x>mx) mx=x; } } cout<<mx<<"\n"; }//end while return 0; } |