BZOJ3675 & Rokua 3648 & uoj104:[apio2014] Sequence Segmentation--the puzzle

Source: Internet
Author: User

https://www.lydsy.com/JudgeOnline/problem.php?id=3675

https://www.luogu.org/problemnew/show/P3648

http://uoj.ac/problem/104

PS: The problem surface and the solution for Ullo and uoj version, Bzoj please consciously the "output procedure" deleted.

Little H has recently hooked up to a game of delimited sequences. In this game, small h needs to divide a series of non-negative integers of length n into k+1 non-empty subsequence sequences. In order to get the k+1 subsequence, the small H needs to repeat the following steps of K: 1. Small h first selects a sequence longer than 1 (at the beginning of the small h only a sequence of length n-that is, the entire sequence obtained at the beginning); 2. Select a location, And through this position the sequence is divided into two consecutive non-empty new sequences. After each of these steps, small h will get a certain score. This fraction is the product of the elements and in two new sequences. Small h wants to choose the best way to divide, so that after K-wheel, the total score of small h is the largest.

Reference: Luo gu (although not counted as reference emmm just slope optimization write kneeling to debug with).

It is not difficult to testify that the answer is fixed so long as the split point is fixed, so O (kn^2) is not difficult to think.

Make s[i] represent the prefix of the first I and then we have:

F[k][i]=max (f[k][i],f[k-1][j]+ (S[i]-s[j]) *s[j])

This equation can obviously be optimized for slope, maintaining a monotone non-additive sequence that makes k<j<i.

Ignoring the previous dimension of F, when f[k]+ (S[i]-s[k]) *s[k]<=f[j]+ (S[i]-s[j]) *s[j], the K is ejected from the first team.

So g[k,j]= (F[K]-F[J]+SQR (S[j])-SQR (S[k])/(S[j]-s[k]) <=s[i] will pop up K.

Also consider G[k,j]>=g[j,i] when the J ejected, give proof.

Obviously when G[j,i]<=s[i] J is not excellent.

When G[k,j]>=g[j,i]>s[i] K better than J still eject J.

I also naive want to maintain monotonous non-reduction sequence results of various wonderful emmm error ...

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespaceStd;typedefLong LongLl;typedefDoubleDL;Const intn=1e5+5;Const intk=205; inlineintRead () {intx=0, w=0;CharCh=0;  while(!isdigit (CH)) {w|=ch=='-'; ch=GetChar ();}  while(IsDigit (CH)) X= (x<<3) + (x<<1) + (ch^ -), ch=GetChar (); returnw?-x:x;} ll f[2][n];intn,k,nxt[n][k],q[n],s[n],l,r,now=1, pre=0; inline ll Sqr (ll K) {returnk*K;} Inline DL Suan (intJintk) {    if(S[j]==s[k])return-1e18; intI=Pre; return(F[I][K]-F[I][J]+SQR (S[j])-SQR (S[k])/(DL) (s[j]-s[k]);}intMain () {n=read (), k=read ();  for(intI=1; i<=n;i++) s[i]=s[i-1]+read ();  for(intj=1; j<=k;j++) { now^=1, pre^=1; l=r=0;  for(intI=1; i<=n;i++){             while(L<r&&suan (q[l],q[l+1]) <= (DL) s[i]) l++; intt=Q[l]; F[now][i]=f[pre][t]+ (LL) (S[i]-s[t]) *s[t];nxt[i][j]=T;  while(L<r&&suan (q[r-1],q[r]) >=suan (q[r],i)) r--; q[++r]=i; }} printf ("%lld\n", F[now][n]); inttmp=Nxt[n][k];  while(k) {printf ("%d", TMP); TMP=nxt[tmp][--K]; }    return 0;}

+++++++++++++++++++++++++++++++++++++++++++

+ This article luyouqi233. +

+ Welcome to visit my blog: http://www.cnblogs.com/luyouqi233/+

+++++++++++++++++++++++++++++++++++++++++++

BZOJ3675 & Rokua 3648 & uoj104:[apio2014] Sequence Segmentation--the puzzle

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.