题解:P10463 【重题】
Chen_Three · · 题解
题解:P10463 【重题】
前铺知识:二位前缀和
s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j] 每次枚举求最大值
话不多说上代码
第一篇题解求过
#include<bits/stdc++.h>
#define MAXN 130
#define LL long long
using namespace std;
LL a[MAXN][MAXN];
LL s[MAXN][MAXN];
int main() {
ios::sync_with_stdio(0);
int N;
cin >> N;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) {
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
LL ans = INT_MIN;
for (int x1 = 1; x1 <= N; x1++) {
for (int y1 = 1; y1 <= N; y1++) {
for (int x2 = x1; x2 <= N; x2++) {
for (int y2 = y1; y2 <= N; y2++) {
ans = max(ans, s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 - 1][y1 - 1]);
}
}
}
}
cout << ans;
return 0;
}