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.
32 lines
692 B
32 lines
692 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
const int N = 330;
|
|
int n;
|
|
int a[N][N], dp[N];
|
|
int res = INT_MIN;
|
|
|
|
int main() {
|
|
cin >> n;
|
|
// 前缀和(竖直方向)
|
|
for (int i = 1; i <= n; i++) {
|
|
for (int j = 1; j <= n; j++) {
|
|
cin >> a[i][j];
|
|
a[i][j] += a[i - 1][j];
|
|
}
|
|
}
|
|
// 降维变成一维dp
|
|
for (int i = 0; i <= n - 1; i++) {
|
|
for (int j = i + 1; j <= n; j++) {
|
|
for (int k = 1; k <= n; k++) {
|
|
dp[k] = max(a[j][k] - a[i][k], dp[k - 1] + a[j][k] - a[i][k]);
|
|
res = max(res, dp[k]);
|
|
}
|
|
}
|
|
}
|
|
|
|
cout << res;
|
|
|
|
return 0;
|
|
}
|