You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
764 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int N = 130;
int a[N][N], s[N][N];
int main() {
int n, res = INT_MIN;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
2 years ago
s[i][j] = s[i - 1][j] + a[i][j]; // 利用一维前缀和把当前第j列前面的1~j-1列的值累加和压缩到第j列每列都是如此处理
2 years ago
}
2 years ago
// O(N^3)算法
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) {
2 years ago
int _s = 0;
2 years ago
for (int k = 1; k <= n; k++) {
2 years ago
_s = max(_s, 0) + s[i][k] - s[j][k];
res = max(res, _s);
}
}
}
cout << res << '\n';
return 0;
}