ykj12

root 站长 2024-01-26 15:03:14 1
#include <iostream>
using namespace std;
const int SIZE = 100;
int matrix[SIZE + 1][SIZE + 1];
int rowsum[SIZE + 1][SIZE + 1]; /* rowsum[i][j]记录第i行前j个数的和 */
int m, n, i, j, first, last, area, ans;
int main()
{
	cin >> m >> n;
	for ( i = 1; i <= m; i++ )
		for ( j = 1; j <= n; j++ )
			cin >> matrix[i][j];
	ans = matrix [1][1];
	for ( i = 1; i <= m; i++ )
		 rowsum[i][0]=0;
		for ( i = 1; i <= m; i++ )
			for ( j = 1; j <= n; j++ )
				rowsum[i][j] = rowsum[i][j-1]+matrix[i][j];
	for ( first = 1; first <= n; first++ )
		for ( last = first; last <= n; last++ )
		{
			 area=0;
			for ( i = 1; i <= m; i++ )
			{
				area +=  rowsum[i][last]-rowsum[i][first-1];
				if ( area > ans )
					ans = area;
				if ( area < 0 )
					area = 0;
			}
		}
	cout << ans << endl;
	return(0);
}
{{ vote && vote.total.up }}