Returns the maximum number of sub-arrays in the array

Source: Internet
Author: User

I. Title:

Expands on an existing array to find the sum of the largest subarray of the end-to-end:

Two. Requirements:

1) Enter a one-dimensional shape array with positive numbers in the array and negative values.

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

3) The maximum value of all sub-arrays is evaluated.

4) Pair programming requirements: two pairs of pair to complete the programming task. One person is responsible for the program analysis, one person is responsible for code programming code review and Code test plan. Publish a blog post about the process, experience, and how to resolve conflicts between two people (attach a work photo of the development).

Three. Member: Kong Weichun Cui Peng Bo

Four. Analysis of ideas:

This time the programming development is based on the last one-dimensional array, I and Tripenberg (ID: the moment) began a serious discussion, and then combined with the class discussion, how can be in a one-dimensional array on the basis of the original, coupled with the end-to-end condition, while reducing the complexity of time, The approximate idea of this method is: Iterate through the array of each number of the first number into the last number, the specific algorithm is a[i-1]=a[i], this becomes a new one-dimensional array, output the maximum number of sub-arrays per array, and then compare each output and, find the largest.

Five. Source code:

1#include"stdafx.h"2 int_tmain (intARGC, _tchar*argv[])3 {4     return 0;5 }6#include <iostream>7 using namespacestd;8 intMaxsum (intAintN//defines a method for finding the largest subarray of a one-dimensional array9 {Ten     intsum =0; One  A     intb =0; -  -      for(inti =0; i<n; i++) the     { -         if(b<0) -b =A[i]; -         Else +B + =A[i]; -         if(sum<b) +sum =b; A     } at     returnsum; - } -  - intMain () - { -     intN, temp, B; in     intsum =0; -     inti; to     inta1, A2; +cout <<"Please enter the length of the array:"<<Endl; -CIN >>N; thecout <<"Please enter each element of the array (separated by spaces):"<<Endl; *     int*a =New int[n]; $ Panax Notoginseng      for(i =0; i<n; i++) -     { theCIN >>A[i]; +     } Acout <<"The maximum number of sub-arrays in this end-to-end array is in the following cases:"<<Endl; thecout <<"1th Way:"<<Endl; +      for(i =0; i<n; i++) -     { $cout << A[i] <<"  "; $     } -cout <<"the maximum number of sub-arrays to be evaluated is:"<< Maxsum (A, N) <<Endl; -A1 =Maxsum (A, n); the      for(b =1; b<n; b++) -     {Wuyitemp = a[0]; the          for(i =1; I <= N; i++) -         { WuA[i-1] =A[i]; -  About         } $A[n-1] =temp; -cout <<"Section"<< B +1<<"type of method:"<<Endl; -          for(i =0; i<n; i++) -         { Acout << A[i] <<"  "; +         } thecout <<"the maximum number of sub-arrays is:"<< Maxsum (A, N) <<Endl; -         if(Maxsum (A, N) >=sum) $         { thesum =Maxsum (A, n); the         } the     } theA2 =sum; -cout <<Endl; in     if(A1 >=A2) the     { thecout <<"In summary, the largest sub-array and is:"<< A1 <<Endl; About     } the     Else the     { thecout <<"In summary, the largest sub-array and is:"<< A2 <<Endl; +     } -System"Pause"); the     return 0; Bayi}

Vi.. Operation

Seven, feelings

Enhanced our understanding of each other, so that we cooperate a little more tacit understanding.

Eight, True image

Returns the maximum number of sub-arrays in the 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.