The largest interconnected array of two-dimensional arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.