To find the largest contiguous and

Source: Internet
Author: User

If we want to multiply the product and consider the negative number multiplication and the case of 0 ...!

Continuous product sub-series Max

mi[1] = mx[1] = a[1];          for (int2; I <= n;i++) {            = min (min (a[i],a[i]*mi[i-1]), a[i]*mx[i-1 ]);             = Max (max (a[i],a[i] * mi[i-1]), A[i] * mx[i-1]);        }

#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<cstdlib>#include<stack>#include<cctype>#include<string>#include<malloc.h>#include<queue>#include<map>using namespacestd;Const intINF =0xFFFFFF;Const DoubleESP = 10e-8;Const DoublePi =4* ATAN (1.0);Const intMAXN = -+Ten;Const Long LongMoD =2147483647;Const intDr[] = {1,0,-1,0,-1,1,-1,1};Const intDc[] = {0,1,0,-1,1,-1,-1,1};typedefLong LongLL; ll GAC (ll A,ll b) {returnB?GAC (b,a%b): A;}inta[10000];intMaxsum (intXintY) {///the algorithm is complex NLN (n), f (n) = 2 * F (N/2) +n,f (1) = 1;    if(Y-x = =1)        returnA[x]; intm = x + (y-x)/2; intMM =Max (Maxsum (x,m), Maxsum (m,y)); intL = a[m-1]; intR = a[y-1]; intv =0;  for(inti = m1; I >-1; i--) {v+=A[i]; L=Max (v,l); } v=0;  for(inti = M;i < y;i++) {v+=A[i]; R=Max (R,V); }    returnMax (mm,l+R);}intMain () {#ifndef Online_judge freopen ("Inpt.txt","R", stdin);#endif    intN;  while(~SCANF ("%d",&N)) {        ints[10000]; memset (s),0,sizeof(s)); intMX =-0xfffff; inttt =-1;  for(inti =1; I <= n;i++) {scanf ("%d",&A[i]); S[i]+ = (s[i-1] +A[i]); if(S[i] >=MX) {MX=S[i]; TT=i; }        }        intMi = a[1]; if(TT! =-1){             for(inti =2; i < tt;i++) {///look for the minimum value in front of the largest and most foundMi =min (mi,[i]); }} cout<<"D1:"<< Mx-mi <<Endl; intxx = Maxsum (1, n+1); cout<<"D2:"<< xx <<Endl; }    return 0;}
Continuous sub-sequence Max and

To find the largest contiguous and

Related Article

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.