-
Notifications
You must be signed in to change notification settings - Fork 0
/
poj1050.cpp
41 lines (38 loc) · 923 Bytes
/
poj1050.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
#include<iostream>
#include<cstring>
#define N 100+5
using namespace std;
void solution(int A[N][N], int n);
int main() {
int A[N][N] = {0};
int n;
cin >> n;
for (int i=1; i <= n; ++i) {
for (int j=1; j <= n; ++j) {
cin >> A[i][j];
}
}
solution(A, n);
return 0;
}
void solution(int A[N][N], int n) {
int maxi= 0x80000000;
int sum[N] = {0};
int tmp[N] = {0};
for (int i=1; i <= n; ++i) {
memset(sum, 0, sizeof(sum));
memset(tmp, 0, sizeof(tmp));
for (int k=i; k <= n; ++k) {
for (int j=1; j <= n; ++j) {
tmp[j] += A[k][j];
if (sum[j-1] >= 0) {
sum[j] = sum[j-1]+tmp[j];
} else {
sum[j] = tmp[j];
}
maxi = sum[j] > maxi ? sum[j] : maxi;
}
}
}
cout << maxi <<endl;
}