AcWing 126. 最大的和
原题链接
简单
作者:
hai阿卢
,
2021-02-23 12:01:19
,
所有人可见
,
阅读 265
#include<iostream>
using namespace std;
const int N = 110;
int a[N][N], s[N][N];
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
cin >> a[i][j];
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
}
}
int mx = -0x3f3f3f3f;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
for(int ii = i; ii <= n; ii++)
{
for(int jj = j; jj <= n; jj++)
{
mx = max(mx, s[ii][jj] - s[i - 1][jj] - s[ii][j - 1] + s[i - 1][j - 1]);
}
}
}
}
cout << mx << endl;
return 0;
}