这暴力直接过了!!!
代码如下:
#include <bits/stdc++.h>
using namespace std;
int c[1001][1001], s[1001][1001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> c[i][j];
s[i][j] += s[i - 1][j] + s[i][j - 1] + c[i][j] - s[i - 1][j - 1];
}
}
int ans = -2147483647;
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= n; ++y) {
for (int x2 = x + 1; x2 <= n; ++x2) {
for (int y2 = y + 1; y2 <= n; ++y2) {
ans = max(s[x2][y2] - s[x - 1][y2] - s[x2][y - 1] + s[x - 1][y - 1], ans);
}
}
}
}
cout << ans;
return 0;
}
只用了前缀和,其他什么也没用!