Bzoj 3675 [Apio2014] Sequence Segmentation

Source: Internet
Author: User

Solving: slope optimization, maintenance on convex hull, similar to upper right half circle

Scrolling array optimization space, DP time record decision point

Note: note Sum[i]-sum[j] may ==0

The guy gave 32 points to the QWQ.

In fact, this code has a bug but the data is not card

For removing the 0 element directly then DP may make the sequence less than M

#include <iostream> #include <cstdio> #include <cstring>using namespace std;const int maxn=100009; const int Maxm=209;typedef long long lint;int n,m; Lint S[maxn];int REF[MAXN]; Lint F[MAXN]; Lint g[maxn];int P[maxn][maxm];int Q[MAXN]; Lint getk (int i) {return g[i]-s[i]*s[i];} void Putans (int x,int y) {if (y==0) Return;putans (p[x][y],y-1);p rintf ("%d", ref[x]);} int main () {scanf ("%d%d", &n,&m), ++m;int cnt=0;for (int i=1;i<=n;++i) {Lint x;scanf ("%lld", &x); if (x==0) Continue;++cnt;s[cnt]=s[cnt-1]+x;ref[cnt]=i;} N=cnt;int h,t;for (int j=2;j<=m;++j) {q[h=t=1]=j-1;for (int i=j;i<=n;++i) {while (h<t) && (GETK (q[h+1 ])-GETK (Q[h])) >-s[i]* (S[q[h+1]]-s[q[h])) ++h;//printf ("%d%d%d\n", J,i,q[h]) f[i]=g[q[h]]+ (S[I]-S[Q[H)] [H]]; P[i][j]=q[h];while (h<t) {int a=q[t-1],b=q[t];if (1.0* (GETK (b)-getk (a))/(S[b]-s[a]) <1.0* (GETK (i)-GETK (b))/(s [I]-s[b])--t;else break;} Q[++t]=i;} for (int i=1;i<=n;++i) {g[i]=f[i];f[i]=0;}} printf ("%lld\n", G[n]);//putans (p[n][m],m-1);//printf ("\ n "); return 0;} 

  

Bzoj 3675 [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: 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.