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
935 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 125;
int n; // 边长
int ans = INT_MIN;
int a[N][N]; // 记录矩形
int s[N]; // s[k]表示[i,j]行范围内第k列的前缀和
int dp[N];
void getDp() {
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; i++) {
dp[i] = max(s[i], dp[i - 1] + s[i]); // 只有当前列或者加上上前面val最大的矩形
ans = max(ans, dp[i]);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++) { // 枚举起始行
memset(s, 0, sizeof s); // 重置前缀数组
for (int j = i; j <= n; j++) { // 枚举末尾行
for (int k = 1; k <= n; k++) // 枚举列
s[k] += a[j][k];
getDp();
}
}
cout << ans << endl;
return 0;
}