URAL 1146 Maximum Sum 最大子矩阵和

时间:2021-04-18 15:48:18

题目:click here

 #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int INF = 0x3f3f3f3f;
const int M = 2e2+; int n;
int a[M][M]; // a[i][j] 表示从[i][0]到[i][j]的和
int main() {
while( ~scanf("%d", &n ) ) {
memset( a, , sizeof(a) );
for( int i=; i<=n; i++ ) {
for( int j=; j<=n; j++ ) {
scanf("%d", &a[i][j] );
a[i][j] += a[i][j-];
}
}
int ret = -INF;
for( int i=; i<=n; i++ ) {
for( int j=; j<i; j++ ) {
int sum = ;
for( int h=; h<=n; h++ ) {
sum += a[h][i] - a[h][j];
ret = max( ret, sum );
if( sum < ) sum = ;
}
}
}
printf("%d\n", ret );
}
return ;
}