The topic description is given a positive integer n (n <= 100), and then input an N * n matrix. Calculate the maximum weighted rectangle in the matrix, that is, each element of the matrix has a weight value, which is defined in the Integer Set. Find a rectangle from it. The rectangle size is unlimited, which is the sum of all elements in it. Each element of the matrix belongs to [-127,127]. For example, 0-2-7. 0 is in the lower left corner: 9 29 2-6 2-4 1-4 1-4 1-1 8-1 8 0-2 and 15 input format First line: N, next is the matrix of N rows and n columns. Sum of the largest rectangle (Child matrix) in the output format. Sample input 4 0-2-7 0 9 2-6 2-4 1-4 1-1 8 0-2 sample output 15
The largest child rectangle is similar to eating watermelon.
Accode:
# Include <cstdio> # include <cstring> # include <cstdlib> # include <bitset> Using STD: Max; const char fi [] = "rqnoj106.in "; const char fo [] = "rqnoj106.out"; const int maxn = 110; const int max = 0x3fffff00; const int min =-Max; int sum [maxn] [maxn]; int W [maxn] [maxn]; int N, ans; void init_file () {freopen (FI, "r", stdin); freopen (FO, "W ", stdout);} void readdata () {scanf ("% d", & N); For (INT I = 1; I <n + 1; ++ I) for (Int J = 1; j <n + 1; ++ J) scanf ("% d", & W [I] [J]);} void work () {for (INT I = 1; I <n + 1; ++ I) for (Int J = 1; j <n + 1; ++ J) sum [I] [J] = sum [I-1] [J] + W [I] [J]; ans = 0; For (INT I1 = 0; i1 <n; ++ I1) for (INT I2 = I1 + 1; I2 <n + 1; ++ I2) {int max = sum [I2] [1]-sum [I1] [1]; int TMP = max; For (Int J = 2; j <n + 1; ++ J) {TMP = max (0, TMP); TMP + = sum [I2] [J]-sum [I1] [J]; max = max (max, TMP);} ans = max (max, ANS);} printf ("% d", ANS);} int main () {init_file (); readdata (); work (); exit (0 );}