# [bzoj1911][Apio2010]特别行动队

## 题解

$dp[i]=max(dp[j]+a(s[i]-s[j])^2+b(s[i]-s[j])+c)$

$设j< k,且j比k优$

$dp[j]-2as[i]s[j]+as[j]^2-bs[j]<=dp[k]-2as[i]×s[k]+as[k]^2-bs[k]$

$dp[j]-dp[k]+a×(s[j]^2-s[k]^2)-b×(s[j]-s[k])<=2a(s[j]-s[k])×s[i]$

$\because 2a×(s[j]-s[k])>0$

$\therefore \frac{dp[j]-dp[k]+a×(s[j]^2-s[k]^2)-b×(s[j]-s[k])}{2a×(s[j]-s[k])}<=s[i]$

## Code

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
{
int sum=0,p=1;char ch=getchar();
while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
if(ch=='-')p=-1,ch=getchar();
while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
return sum*p;
}

const int maxn=1e6+20;

int n;
ll s[maxn];
ll dp[maxn];
ll a,b,c;

void init()
{

}

#define sqr(x) ((x)*(x))

double count(int j,int k)
{
return (double)(dp[j]+a*sqr(s[j])-b*s[j]-dp[k]-a*sqr(s[k])+b*s[k])/(2*a*(s[j]-s[k]));
}

void doing()
{
REP(i,1,n)
{
dp[i]=dp[x]+a*sqr(s[i]-s[x])+b*(s[i]-s[x])+c;
q[++tail]=i;
}
printf("%lld\n",dp[n]);
}

int main()
{
init();
doing();
return 0;
}


posted @ 2017-10-23 17:27  Deadecho  阅读(105)  评论(0编辑  收藏  举报