"Slope optimization" BZOJ1010 [HNOI2008] Toy boxing toy

Source: Internet
Author: User

"The main topic"

Professor P has the number 1 ... N Toys, Part I toy length is ci. For ease of finishing, Professor P requires that the number of toys in a one-dimensional container be continuous. If the toy I toys to the J toy into a container, then the length of the container will be X=j-i+sigma (Ck) i<=k<=j the cost of making the container is related to the length of the container, if the container length is x, the production cost is (X-L) ^2. Where L is a constant. Minimum cost.

Ideas

Too lazy to say, the WC Song Nio Teacher's courseware to carry a bit.

Song Nio Teacher said very well, when the first time to listen to slope optimization of the WC listen to him after the second understand, after a few months to digest.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong LongLL;7 Const intmaxn=50000+ -;8 intn,l;9 intC[MAXN];Ten LL S[MAXN],G[MAXN],X[MAXN],Y[MAXN],F[MAXN]; One   A ll Square (ll x) - { -     returnx*x; the } -   - DoubleSlopintIintj) - { +     return((Y[j]-y[i])/(x[j]-x[i])); - } +   A voidDP () at { -Memset (F,0,sizeof(f)); -     intHead=0, tail=0; -     intQ[MAXN]; -q[head]=0; -      for(intI=1; i<=n;i++) in     { -y[i]=f[i-1]+Square (X[i]); to          while(head+1<tail && Slop (q[tail-2],q[tail-1]) >slop (q[tail-1],i)) tail--; +q[tail++]=i; -          while(head+1<tail && Slop (q[head],q[head+1]) <2.0*g[i]) head++; thef[i]=f[q[head]-1]+square (g[i]-X[q[head]]); *     } $ }Panax Notoginseng   - voidInit () the { +scanf"%d%d",&n,&l); Amemset (s),0,sizeof(s)); the      for(intI=1; i<=n;i++) +     { -scanf"%d",&c[i]); $s[i]=s[i-1]+C[i]; $g[i]=s[i]+i-l; -x[i]=s[i-1]+i; -     } the } -  Wuyi voidPrintans () the { -printf"%lld", F[n]);  Wu } -   About intMain () $ { - init (); - DP (); - Printans (); A     return 0; +}

"Slope optimization" BZOJ1010 [HNOI2008] Toy boxing toy

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.