# Sub-array 2

Source: Internet
Author: User

Teammate: http://home.cnblogs.com/u/Megau/

First, analysis

First, an array of length n is enlarged by twice times, that is, after the array is followed by an array of the same size, then the length is n, and the elements at the beginning of the array are the cells of the original array, forming n arrays. The n array is then followed by the maximum Subarray, and then the maximum and in this heap is found.

Second, the Code

`str1="4-2 3-1-1"Print"Please enter an array"str1=raw_input () counter_1=0STR2=str1+" "+STR1STR2=Str2.split ()#Print str2counter_1=0 forIinchstr2:counter_1=counter_1+1counter_1=counter_1/2#Print counter_1answer_array=[0]*counter_1 forJinchRange (0,counter_1): Str3=str2[j:j+counter_1]#print "Str3", Str3sum_record_unexcept=0 Str3[0]=Int (str3[0]) Sum_constant_add=0 forIinchstr3:i=Int (i) sum_record_unexcept=Max (sum_record_unexcept,sum_constant_add) Sum_constant_add=max (sum_constant_add+i,i) Answer_array[j]=Max (sum_constant_add,sum_record_unexcept)#print "Answer_array[i]", Answer_array[j]#print "Answer", Answer_arrayMaxment=Answer_array[0] forIinchAnswer_array:if(maxment<i): Maxment=IPrint"The maximum value is", maxment`

Three

Sub-array 2

Related Keywords:

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.