1234ZSL @ 2025-01-10 22:32:21
代码如下:
#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;
}
只用了前缀和,其他什么也没用!
by rnf5114 @ 2025-01-10 22:39:23
@1234ZSL120的四次方也才2e8而且又跑不满肯定能过啊
by 1234ZSL @ 2025-01-10 22:41:59
@rnf5114 所以我建议加强数据,标签还挂着DP
by Liziya @ 2025-01-11 00:25:50
@1234ZSL DP只用