Slope optimization Topic 4--bzoj 1911: [Apio2010] Special Action Team

Source: Internet
Author: User

"Original question"

1911: [Apio2010] Special Action Team time limit: 4 Sec Memory Limit: MB
Submit: 2134 Solved: 911
[Submit] [Status] Descriptioninputoutputsample Input4
-1 10-20
2 2 3 4Sample Output9HINT


"Analysis" as long as I follow the topic ahead, this problem is really too water. God horse no reference, formula casually push.

The Ishi equation is F[i]=max (f[j]+a* (Sum[i]-sum[j]) ^2+b* (Sum[i]-sum[j]) +c)
Set K ratio J Excellent.
F[k]+a (Sum[i]-sum[k]) ^2+b (Sum[i]-sum[k]) +c>f[j]+a (Sum[i]-sum[j]) ^2+b (Sum[i]-sum[j]) +c
F[K]-2*A*SUM[I]*SUM[K]+A*SUM[K]^2-B*SUM[K]>F[J]-2*A*SUM[I]*SUM[J]+A*SUM[J]^2-B*SUM[J]
f[k]-f[j]+a* (sum[k]^2-sum[j]^2) +b* (Sum[j]-sum[k]) >2*a*sum[i]* (Sum[k]-sum[j])
(f[k]-f[j]+a* (sum[k]^2-sum[j]^2) +b* (Sum[j]-sum[k])/2/(Sum[k]-sum[j])/a<sum[i]

Code

#include <cstdio> #include <algorithm>using namespace Std;long long n,a[1000005],f[1000005],q[1000005], Sum[1000005],ans,h,t,i,a,b,c,j;long long M (long long x) {return x*x;} Double Xie (Long long K,long long j) {  double temp= (f[k]-f[j]+a* (M (Sum[k])-M (Sum[j])) +b* (Sum[j]-sum[k]) +0.0)/2.0/( SUM[K]-SUM[J]/A;  return temp;} int main () {  scanf ("%lld", &n);  scanf ("%lld%lld%lld", &a,&b,&c);  for (i=1;i<=n;i++)    scanf ("%lld", &a[i]), sum[i]=sum[i-1]+a[i];  f[0]=0;h=t=1ll;q[1]=0;  for (i=1;i<=n;i++)  {    while (H<t&&xie (Q[h+1],q[h]) <=sum[i])       h++;    F[i]=f[q[h]]+a*m (Sum[i]-sum[q[h]]) +b* (Sum[i]-sum[q[h]]) +c;    while (H<t&&xie (Q[t],q[t-1]) >xie (i,q[t])) t--;      q[++t]=i;    }    printf ("%lld", F[n]);  return 0;}

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.