bjoj1911 [Apio2010] Sequence Segmentation

Source: Internet
Author: User

1911: [Apio2010] Special Action Team time limit:4 Sec Memory limit:64 MB
submit:4486 solved:2140
[Submit] [Status] [Discuss] Description input Output Sample input4
-1 10-20
2 2 3 4Sample Output9HINT

Source

[Submit] [Status] [Discuss]

Transformation conditions, digging in-depth information, the answer is actually equal tok+1 segment 22 multiplied (multiplication principle YY), unrelated to the order of the cut,ans=σCj * (CI-CJ);; (ans=∑ans=∑ Section i x front I-1 of the paragraph); so UnderK stage to dynamically plan, so that F[i][j] represents the first J number into the maximum score of I segment, then there isF[i] [J]=Max{f[i]1][k ]+c[k]x (C[J]? C[k])}; then use the scrolling array to optimize the slope: AttentionC[i] is likely to be 0, (0 in the equation ), so do not getx, multiply with the cale () function;

1#include <algorithm>2#include <iostream>3#include <iomanip>4#include <cstdlib>5#include <cstring>6#include <cstdio>7#include <vector>8#include <cmath>9#include <queue>Ten#include <stack> One#include <map> A#include <Set> - #definell Long Long - #defineRep (i,a,b) for (register int i=a;i<=b;++i) the #defineRe Register - using namespacestd; - Const intn=100010; -ll dp[2][n],c[n]; + intN,q[n]; - inline ll gi () + { All ret=0;CharCh=GetChar (); at      while(ch<'0'|| Ch>'9') ch=GetChar (); -      while(ch>='0'&&ch<='9') ret=ret*Ten+ch-'0', ch=GetChar (); -     returnret; - } -ll Getnum (intNowintIintBJ) { -     returnDp[!bj][i] + c[i]* (c[now]-c[i]); in } - BOOLCaleintL1,intL2,intL3,intBJ) { toll b1= Dp[!bj][l1]-c[l1]*c[l1],b2=dp[!bj][l2]-C[L2]*C[L2], B3=DP[!BJ][L3]-C[L3]*C[L3];//Bug +     return(B3-B2) * (C[l1]-c[l2]) <= (B2-B1) * (c[l2]-C[l3]); - } the intMain () * { $ Panax NotoginsengN=gi ();intk=gi (); -Rep (I,1, n) c[i]=gi (), c[i]+=c[i-1]; theReintbj=1, Hd,tl; +      for(Reintu=1; u<=k;u++) { Abj=!BJ; theHd=tl=0; q[0]=0; +          for(ReintI=1; i<=n;i++) { -              while(hd+2<=tl&&cale (q[tl-2],q[tl-1],Q[TL],BJ)) q[tl-1]=q[tl--];// $              while(Hd<tl&&getnum (I,Q[HD],BJ) <=getnum (i,q[hd+1],BJ)) hd++; $dp[bj][i]=Getnum (I,Q[HD],BJ); -q[++tl]=i; -         } the     } -printf"%lld", Dp[bj][n]);Wuyi     return 0; the}

bjoj1911 [Apio2010] 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: 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.