-
Notifications
You must be signed in to change notification settings - Fork 2
/
10074.cpp
61 lines (49 loc) · 998 Bytes
/
10074.cpp
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
#include<stdio.h>
#define Dif(i,j,k) (Table[i+k][j] - Table[i][j])
#define MAXN 105
int N,M,MAX;
int Table[MAXN][MAXN];
void ReadCase() {
int i, j;
for(i = 1; i<=N; i++)
for(j = 0; j<M; j++){
scanf("%d",&Table[i][j]);
if(Table[i][j] ==1)
Table[i][j] = -1001;
else Table[i][j] = 1;
}
}
void Cal() {
int i, j, k, t;
for(i = 1; i<=N; i++){
for(j = 0; j<M; j++)
Table[i][j] = Table[i][j] + Table[i-1][j];
}
MAX = Table[1][0];
for(k = 1; k<=N; k++) {
for(i = 0; i<=N-k; i++){
for(t = 0, j = 0; j<M; j++) {
if(t>=0) t+= Dif(i,j,k);
else t = Dif(i,j,k);
if(t>MAX) MAX = t;
}
}
}
MAX<0?printf("0\n"):printf("%d\n",MAX);
}
void FREE() {
int i, j;
for(i = 0; i<=N; i++)
for(j = 0; j<=M; j++)
Table[i][j] = 0;
}
int main() {
int f = 0;
while(scanf("%d%d",&N,&M) == 2) {
if(!N && !M) break;
if(f++) FREE();
ReadCase();
Cal();
}
return 0;
}