无脑操作题,由于n<=100,直接枚举所有的子矩阵即可。
#include#include using namespace std;//Mystery_Sky//#define M 1000int f[M][M], a[M][M];int n, ans, maxn;int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { scanf("%d", &a[i][j]); f[i][j] = f[i][j-1] + a[i][j]; } for(int i = 1; i <= n; i++) { for(int j = i; j <= n; j++) { maxn = 0; for(int k = 1; k <= n; k++) { maxn += f[k][j] - f[k][i-1]; ans = max(maxn, ans); if(maxn < 0) maxn = 0; } } } printf("%d\n", ans); return 0;}