Design ideas: Divide the number of rows into a few one-dimensional arrays, for the one-dimensional array, the sum of their largest contiguous array, and record the maximum continuous array of the first and last position, and then determine the maximum continuous array of several one-dimensional array position or inclusion, and finally add not included in the positive number, The sum of the outputs before the output is OK.
1#include <iostream>2 using namespacestd;3 4 intZuida (intNintA[],int*SM,int*mm)5 {6 intb[ -] = {0};//Initialize7 intI, sum1 =0, Max1 =0;8 for(i =0; i<n; i++)//determining the maximum value9 {Ten if(sum1<0) One { ASUM1 =A[i]; - } - Else the { -SUM1 = sum1 +A[i]; - } -B[i] =sum1; + } -MAX1 = b[0]; + for(i =0; i<n; i++) A { at if(max1<B[i]) - { -Max1 =B[i]; -*MM =i; - } - } in for(i = *mm; I >=0; i--) - { to if(B[i] = =A[i]) + { -*SM =i; the Break; * } $ }Panax Notoginseng returnmax1; - } the + voidMain () A { the intm, N, I, J, SM, MM, T2; + intsum, max; - intup[ -], down[ -], t[ -]; $ inta[ -][ -], b[ -]; $cout <<"Enter rows and columns for a two-dimensional array"; -CIN >> M >>N; -cout <<"Enter a two-dimensional array:"<<Endl; the for(i =0; i<m; i++) - {Wuyi for(j =0; j<n; J + +) the { -CIN >>A[i][j]; Wu } - } About $ for(i =0; i<m; i++) - { - for(j =0; j<n; J + +) - { AB[J] =A[i][j]; + } thesum = Zuida (n, b, &sm, &mm);//calling Functions -Up[i] =SM; $Down[i] =mm; theT[i] =sum; the the } theT2 = t[0]; - for(i =0; i +1<m; i++) in { the if(Up[i] <= down[i +1] && Down[i] >= up[i +1]) the { AboutT2 + = T[i +1]; the } the for(j = up[i]; J<up[i +1]; J + +) the { + if(A[i +1][j]>0) T2 + = A[i +1][J];//distinguishing independent positive numbers - } the Bayi } thecout << T2 <<Endl; the -}
Feelings: Learning is boundless, study can not relax, can not be complacent ...
The largest interconnected array of two-dimensional arrays