Test instructions: Maximum sub-matrices and problems.
Solution: N^2 Enumeration of a matrix, as follows
A11 A12 ... a1i ... a1j ... a1n
A21 A22 ... a2i ... a2j ... a2n
...
An1 an2 ... ani ... anj ann
To cite a matrix from I to J, add the value of each row and then get an array of {a1ij, A2ij, ..., anij}, the maximum number of sub-segments and (equation: maxn[i] = max (Maxn[i-1] + a[i], a[i])), and the maximum value of all the maximum child segments is the answer.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;int main () {int n; int a[105][105]; while (~SCANF ("%d", &n)) {int ans =-2000000; for (int i = 0; i < n; i++) for (int j = 0; J < N; j + +) scanf ("%d", &a[i][j]); for (int i = 0, i < n; i++) for (int j = i; J < N; j + +) {int Maxx =-2000000; for (int k = 0; k < n; k++) {int sum = 0; for (int l = i; l <= J; l++) sum + = A[k][l]; Maxx = max (maxx + sum, sum); ans = max (Maxx, ANS); } } printf ("%d\n", ans); } return 0;}
PS: Overflow after initializing Maxx to Int_min plus negative number Qaq
POJ 1050 to the Max