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.

33 lines
792 B

2 years ago
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
int g[N][N];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
cin >> g[i][j];
// 累加出并记录同一列的前缀和
g[i][j] += g[i - 1][j];
}
int res = -INF;
// 枚举边界12
for (int i = 1; i <= n; i++) // 起始行
for (int j = i; j <= n; j++) { // 终止行
// 枚举边界p
int last = 0;
for (int k = 1; k <= n; k++) {
last = max(last, 0) + g[j][k] - g[i - 1][k];
res = max(res, last);
}
}
cout << res << endl;
return 0;
}