bzoj1911 "APIO2010" Special Ops Team

Source: Internet
Author: User

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

Source



Slope Optimization DP




#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long Long#define maxn 1000005using namespace std;int n,l,r;ll a,b,c,q[maxn],f[maxn],s[maxn];inline int Read () {i NT X=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} inline double getk (int x,int y) {return (double) ((F[x]+a*s[x]*s[x]-b*s[x])-(f[y]+a*s[y]*s[y]-b*s[y]))/(double) (s[x]- S[y]);} int main () {n=read (); A=read (); B=read (); C=read (); F (I,1,n) s[i]=s[i-1]+read (); l=r=1;q[1]=0; F (I,1,n) {while (L&LT;R&AMP;&AMP;GETK (q[l],q[l+1]) >a*s[i]*2) l++;f[i]=f[q[l]]+a*s[q[l]]*s[q[l]]-b*s[q[l]]-a*s[ I]*s[q[l]]*2+a*s[i]*s[i]+b*s[i]+c;while (L&LT;R&AMP;&AMP;GETK (Q[r-1],q[r]) &LT;GETK (q[r],i)) r--;q[++r]=i;} printf ("%lld\n", F[n]); return 0;}


bzoj1911 "APIO2010" Special Ops Team

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.