[Bzoj 1010] [Hnoi 2008] Toy packing toy

Source: Internet
Author: User

Compare the base slope optimization DP See the following 2 blog posts

Http://www.cnblogs.com/proverbs/archive/2012/10/06/2713109.html

http://blog.163.com/myq_952/blog/static/863906320112711750378/

Main summary of slope optimization steps

1. Demonstrate the persistence of better decision points for subsequent state impact

2. Slope equation: Generalized to the left is the j,k, the right is the form of I

3. Rules governing the maintenance of queues

4. See if the decision is monotonous, if not, how to maintain

The Code of the subject

1#include <cstdio>2 #defineN 501003 #defineLL Long Long4  5 intN;6 intq[n],h,t;7 LL f[n],c[n],sum[n],g[n],l;8  9LL Sqr (ll a) {returnA *A;}TenLL X (intAintb) {returnF[A]-F[B]+SQR (g[a]+l)-SQR (g[b]+l);} OneLL Y (intAintb) {return 2* (g[a]-g[b]);} A   - intMain () - { thescanf"%d%lld",&n,&l); -l++; -      for(intI=1; i<=n;i++) scanf ("%lld", c+i); -      for(intI=1; i<=n;i++) sum[i]=sum[i-1]+C[i]; +      for(intI=1; i<=n;i++) g[i]=sum[i]+(LL) i; -      for(intI=1; i<=n;i++) +     { A          while(H<t&&x (q[h],q[h+1]) >=y (q[h],q[h+1]) *g[i]) h++; atF[I]=F[Q[H]]+SQR (g[i]-g[q[h]]-l); -          while(H<t&&x (q[t-1],q[t]) *y (q[t],i) >=x (q[t],i) *y (q[t-1],q[t]) t--; -q[++t]=i; -     } -printf"%lld\n", F[n]); -     return 0; in}

[Bzoj 1010] [Hnoi 2008] Toy packing 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.