51Nod 1050 Loop Array Max sub-segment and DP

Source: Internet
Author: User

51Nod 1050 Loop Array Maximum sub-segment and portal

Emmmmm ... I thought it was an array copy for the maximum sub-segment and ... The amount of ... Not...... Think less of the feeling of reverse thinking ...

The maximal sub-segments of the loop array and the conversion into non-circular arrays can be of two kinds, one of the largest sub-segments of the non-cyclic array and (presumably, the kind of continuous, not spanning 1 and n types), and the other is the sum-.

#include <iostream>#include<algorithm>#include<string>#include<string.h>typedefLong Longll;using namespacestd;ll n,res,a[50005],b[50005],crt;ll dp,dpp,sum;intMain () { while(SCANF ("%lld", &n)! =EOF) {Sum=0; CRT =0; LL Minn=0x3f3f3f3f, maxx=-0x3f3f3f3f;  for(inti =1; I <= N; i++) {scanf ("%lld", &A[i]); Sum+=A[i]; B[i]=A[i]; if(A[i] <0) crt++; }        if(crt = = N) Break;  for(inti =1; I <= N; i++) {DP+=A[i]; DPP+=B[i]; if(DP >Maxx) Maxx=DP; if(dpp<Minn) Minn=DPP; if(DP <0) DP=0; if(dpp>0) DPP=0; } printf ("%lld\n", Max (Sum-Minn,maxx)); }    return 0;}

51Nod 1050 Loop Array Max sub-segment and DP

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.