The largest sub-array of program development

Source: Internet
Author: User

First, title: Returns the maximum number of sub-arrays in an integer array and
Second, the experimental ideas:

1. Define an integer array num[n], randomly generate the values of the elements in the array,
2. Define a two-dimensional array arr[n][2],arr[i][0] does not contain the sum of the num[i] sub-array and maximum value, arr[i][1] contains the sum of the num[i] sub-array
3. Randomly generated array num[n]
4. Using the recursive recursion method, call the Max function to calculate arr[i][0],arr[i][1], calculate the case that contains the array element itself and the first subarray without itself, and assign the maximum value to max

Three source code

1#include <iostream>2#include <time.h>3 #defineN 100//the maximum number of set arrays is4 using namespacestd;5 intMain ()6 {    7 Srand ((unsigned) time (NULL)); 8     intnum[n],arr[n][2];//num[] is used to hold an array, arr[i][0] refers to the and of the largest sub-array not including num[i], and arr[i][1] refers to the largest sub-array including num[i] and9     intNum,max;//num is the length of the exponential group and Max is used to store the maximum andTencout<<"Please enter the length of the array:"<<Endl; OneCin>>Num; Acout<<"This array is:"<<Endl; -      for(intI=0; i<num;i++)//randomly generate an array -     { thenum[i]=- -+rand ()% -; -     } -      for(intI=0; i<num;i++) -     { +cout<<num[i]<<" "; -     } +cout<<Endl; Acout<<"Please enter the maximum number of sub-arrays for this array and:"<<Endl; atarr[1][0]=0; -arr[1][1]=num[1];//Initialize arr[i][0],arr[i][1] -      for(intI=0; i<num;i++)//recursive method is used to find the maximum of the sub-array and -     { -arr[i][0]=max (arr[i-1][0],arr[i-1][1]);//Call the Max function to calculate the sum of the maximum values that do not contain the Num[i] sub-array -arr[i][1]=max (arr[i-1][1]+num[i],num[i]);//Call the Max function to calculate the sum of the values of the subarray containing the num[i] sub-array inMax=max (arr[i][0],arr[i][1]); -     } tocout<<max<<Endl; +}

Iv. Results of the experiment

Five Experimental summary

The main purpose of this experiment is to exercise our ability to pair programming, although this code is very easy, but there are a lot of problems.

First, on the problem of hand-brain coordination, write code on the side, such as me, the head of the code has not gone down in-depth thinking, and then the small partners put

The following ideas to solve the problem, let me have been busy knocking, the idea may be a bit uncomfortable, the hand and the brain is not very coordination, making code in the process of coding errors,

But thinking is a bit stagnant, and we need to strengthen practice later.

Second, on the issue of communication, two people may have a quick and slow thinking, there are before, it will inevitably occur differences of opinion, at this time, we both do carefully listen to each other's

Ideas and suggestions to solve problems faster and achieve a win.

Third, on the issue of efficiency, I am a more lazy people, with a small partner to urge me to complete this problem earlier, did not drag to the end, I think two people together very good, mutual supervision

The joys and sorrows are great.

The largest sub-array of program development

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.