First, Title: N Returns the and of the largest subarray in an integer array.
Second, requirements:
(1) n Enter an array of shapes with positive and negative numbers in the array. (2) a contiguous integer or integers in an n array make up a sub-array, each of which has a and. (3) n if array a[0] ... A[j-1] next to each other, allowing a[i-1], ... A[n-1], a[0] ... A[J-1] and the largest. (4) n returns the position of the largest sub-array at the same time. (5) The maximum value of the and of all sub-arrays is evaluated. Requires a time complexity of O (n). Third, the experimental ideas: the idea of a: an array of elements input, construct a new array, the new array is composed of two times the input array, and then according to the one-dimensional array of the method to find out, the premise to add the constraints, the sum of the length of the array must be less than the number of input arrays. Idea two: After entering an array, the largest subarray is obtained, then the first number is queued to the end, and then the maximum word group is started, until the last array element is the first position. Four, the experiment code: Thinking two code:
#include <iostream>using namespacestd;voidMain () {intLength//Number of arrays intN//the length of the array after the changecout<<"Please enter the number of array elements:"<<Endl; CIN>>length; N=2*length; int*a=New int[n];//Defining Arrayscout<<"Please enter the elements of the array:"<<Endl; for(intI=0; i<length;i++)//the For loop enters the elements of the array sequentially{cin>>A[i]; } intmax=a[0];//first define Max and give the element values in the first array ints=0;//defines s value, s value is the sum of the array elements and is compared to the max value for(intI=0; i<length;i++) {s=0; for(intj=i;j<length+i;j++) {s=s+A[j]; if(s>max) {Max=s; }} a[length+i]=A[i]; } cout<<Endl; cout<<"the number of the largest sub-arrays is:"<<Endl; cout<<max<<Endl;}
Five, the experiment: Six, the experiment summarizes: the key of the thought one is to find the restriction condition of the algorithm, how can satisfy the question request, the thought two also cannot return the maximum sub-array position, through this problem analysis and the knot pair development process the problem which appears, we still have many shortcomings, still need to make unremitting efforts. Seven, teammates: Ranghujie, Liu Bojian
Returns the sum of the largest sub-arrays in an array of concatenated integers