Returns the sum of the largest sub-arrays in a two-dimensional integer array

Source: Internet
Author: User

First, the title: Returns the number of the largest subarray in a two-dimensional integer array.

Second, requirements:

(1) Enter a two-dimensional shaping array with positive numbers in the array and negative values.

(2) The two-dimensional array is connected to the end of the line, like a first and last tape.

(3) One or more consecutive integers in the array make up a sub-array, each of which has a and.

(4) The maximum value of the and of all sub-arrays is evaluated.

Third, the problem-solving ideas:

The two same arrays are merged into an array, and the method of finding the maximal subarray of two-dimensional array is solved

Iv. Source code:

#include <iostream>using namespacestd; #include"math.h"voidMain () {intn=5; intm=5; intn=-Ten; intm=Ten; inta[5][Ten]; intb[Ten]; intA=0; intmax=0; intmax=0; cout<<"Please enter an array element:";  for(intI=0; i<n;i++)    {         for(intj=0; j<m;j++) {cin>>A[i][j]; A[i][m+j]=A[i][j]; }    }     for(intI=0; i<n;i++)    {        intH=i;  for(ints=0;s<2*m;s++) {B[s]=0; }         Do        {              intE=0; intC=0; intD=0;  for(intk=0;k<2*m-1; k++) {B[k]=b[k]+A[h][k]; } A=b[0]; Max=b[0];  for(intj=1;j<2*m-1; j + +)            {                if(a<0) {A=B[j]; if(max<A) {Max=A; E=J; C=J; D=e; }                    Else{e=J; }                }                Else                {                                         if((j-d) = =M) { Break; }                    if(b[j]<0)                    {                        if(max<A) {Max=A; C=j-1; D=e; } A=a+B[j]; }                          Else{A=a+B[j]; if(max<A) {Max=A; C=J; D=e; }                          }                      }               }               if(h==0) {MAX=Max; }               Else if(max<Max) {MAX=Max; } h++; } while((h<N)); } cout<<"Maximum number of word groups and for:"<<MAX; }

V. Summary of tasks:

Each time through a tense and interesting programming, see a new program came into being, inevitably excited, through this programming, need to integrate the original knowledge to summarize, one can, oneself also need more efforts to better realize the program's compilation.

Returns the sum of the largest sub-arrays in a two-dimensional integer array

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.