题目传送门
/*
最大子矩阵和:把二维降到一维,即把列压缩;然后看是否满足最大连续子序列;
好像之前做过,没印象了,看来做过的题目要经常看看:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN];
int main(void) //URAL 1146 Maximum Sum
{
//freopen ("D.in", "r", stdin);
int n;
while (scanf ("%d", &n) == )
{
int ans = -INF;
memset (dp, , sizeof (dp));
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
scanf ("%d", &a[i][j]);
}
}
for (int i=; i<=n; ++i)
{
for (int j=; j<=n; ++j)
{
int sum = ;
for (int k=j; k>=; --k)
{
sum += a[i][k];
dp[i][j][k] = max (sum + dp[i-][j][k], sum);
ans = max (ans, dp[i][j][k]);
}
}
}
printf ("%d\n", ans);
}
return ;
}