#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000
int dp[MAX][MAX];
int main()
{
int m, n,t;
cin >> m >> n;
int maxn = -11100;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> t;
dp[i][j] = dp[i - 1][j] + t;
}
}
int s;
//j行k列的和-(i-1)行k列的和
for (int i = 1; i <= m; ++i) {
for (int j = i; j <= m; ++j) {
s = 0;
int k;
for (k = 1; k <= n; ++k) {
s += dp[j][k] - dp[i - 1][k];
maxn = max(maxn, s);
if (s < 0) s = 0;
}
}
}
cout << maxn << endl;
//system("pause");
return 0;
}
最大子矩阵的和(蓝桥杯) 历届试题 最大子阵
最新推荐文章于 2021-03-13 23:44:58 发布