首页 > 其他 > 详细

AC日记——[HNOI2008]玩具装箱toy bzoj 1010

时间:2017-06-16 23:54:28      阅读:398      评论:0      收藏:0      [点我收藏+]

1010

 

思路:

  斜率优化DP;

  跪烂大佬

 

代码:

#include <bits/stdc++.h>
using namespace std;
#define maxn 50005
#define ll long long
ll que[maxn],sum[maxn],dp[maxn],n,l,ai[maxn],a;
inline void in(ll &now)
{
    char Cget=getchar();now=0;
    while(Cget>9||Cget<0)Cget=getchar();
    while(Cget>=0&&Cget<=9)
    {
        now=now*10+Cget-0;
        Cget=getchar();
    }
}
ll G(ll now)
{
    return sum[now]+now;
}
ll Y(ll x,ll y)
{
    return dp[x]+pow(G(x)+a,2)-dp[y]-pow(G(y)+a,2);
}
ll X(ll x,ll y)
{
    return 2*(G(x)-G(y));
}
int main()
{
    in(n),in(l),a=l+1;ll h=0,tail=0;
    for(ll i=1;i<=n;i++) in(ai[i]),sum[i]=sum[i-1]+ai[i];
    for(ll i=1;i<=n;i++)
    {
        while(h<tail&&Y(que[h+1],que[h])<=G(i)*X(que[h+1],que[h])) ++h;
        dp[i]=dp[que[h]]+(G(i)-G(que[h])-a)*(G(i)-G(que[h])-a);
        while(h<tail&&Y(i,que[tail])*X(que[tail],que[tail-1])<=Y(que[tail],que[tail-1])*X(i,que[tail])) --tail;
        que[++tail]=i;
    }
    cout<<dp[n];
    return 0;
}

 

AC日记——[HNOI2008]玩具装箱toy bzoj 1010

原文:http://www.cnblogs.com/IUUUUUUUskyyy/p/7029468.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!