题目链接:点击这里
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<climits>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 110;
int a[maxn][maxn];
int temp[maxn];
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
scanf("%d", &a[i][j]);
int ans = INT_MIN;
for(int i = 1 ; i < n; i++) //起始行
{
memset(temp, 0, sizeof(temp));
for(int j = i; j <= n; j++) //终止行
{
//第i行到第j行降维压缩,利用最大子段和思想处理
int sum = 0, res = INT_MIN;
for(int k = 1; k <= n; k++) //遍历列
{
temp[k] += a[j][k];
sum += temp[k];
if(sum<0) sum = 0;
res = max(res, sum);
}
ans = max(ans, res);
}
}
printf("%d\n", ans);
return 0;
}