bzoj3675: [Apio2014] Sequence Segmentation

Source: Internet
Author: User

Slope optimization. If I can't speak clearly, I'll go to the main idea of the Star God.

I started thinking about an O (kn^3).

is to enumerate K and N, then enumerate the preceding points, and then enumerate the previous points to the current point at which to break the optimal.

and O (kn^2) What the hell?

I find out by drawing (actually someone has told me the problem of distributive law)

This is the last example of a sample break.

(4), (1,3), (4,0), (2,3)

And then the answer is that every number and the other different groups multiply the number of times

The DP equation concludes that: f[i][now]=f[j][now^1]+s[j]* (S[i]-s[j]);

Where now is the scroll array scroll enumeration K of T

Then the slope is optimized.

But there is a dog than the problem, that is s[j1]==s[j2], when the divisor of 0 to be a special sentence

The star-sense God said he found it when he tuned the sample.

But my metaphysics has gone through the examples.

#include <cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>using namespaceStd;typedefLong LongLL; LL a[110000],s[110000],f[110000][2];intNow ;DoubleYintj) {return Double(f[j][now^1]-s[j]*s[j]);}DoubleXintj) {return Double(S[j]);}DoubleSlopeintJ1,intJ2) {return(Y (J1)-y (J2))/(X (J2)-X (J1));}inthead,tail,list[110000];intMain () {intn,m; scanf ("%d%d",&n,&m); s[0]=0;  for(intI=1; i<=n;i++) scanf ("%lld", &a[i]), s[i]=s[i-1]+A[i]; Memset (F,0,sizeof(f)); now=0;  for(intt=1; t<=m;t++)//Section T cut{ Now^=1; Head=1, tail=1; list[head]=T;  for(inti=t+1; i<=n;i++)        {             while(head!=tail&& (Slope (list[head],list[head+1]) <Double(S[i]) | | S[list[head]]==s[list[head+1]]) head++; intj=List[head]; F[i][now]=f[j][now^1]+s[j]* (s[i]-S[j]);  while(head!=tail&& (s[i]==s[list[tail]]| | Slope (list[tail-1],list[tail]) >slope (list[tail],i)) tail--; list[++tail]=i; }} printf ("%lld\n", F[n][now]); return 0;}

bzoj3675: [Apio2014] Sequence Segmentation

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: 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.