# hdu3507 斜率优化学习笔记（斜率优化+dp）

QWQ菜的真实。

$dp[i]=max(dp[i],dp[j]+(sum[i]-sum[j])^2)$

$dp[j]+(sum[i]-sum[j])^2<dp[k]+(sum[i]-sum[k])^2$

$2\times s[i] \times (s[j]-s[k]) > dp[j]+sum[j]^2-dp[k]-sum[k]^2$

int chacheng(Point x,Point y)
{
return x.x*y.y-y.x*x.y;
}
bool count(Point i,Point j,Point k)
{
Point x,y;
x.x=(k.x-i.x);
x.y=(k.y-i.y);
y.x=(k.x-j.x);
y.y=(k.y-j.y);
if (chacheng(x,y)<=0) return true;
return false;
// if ((double)(k.y-j.y)/(double)(k.x-j.x)<(double)(j.y-i.y)/(double)(j.x-i.x)) return true;
//return false;
}
void push(Point x)
{
q[++tail]=x;
}

void pop(int lim)
{
}

qwq因为一些奇奇怪怪的问题$WA$了一上午
xtbl

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define mk make_pair
#define ll long long
#define int long long
using namespace std;
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
const int maxn = 1e6+1e2;
struct Point{
int x,y;
};
Point q[maxn];
int dp[maxn];
int sum[maxn];
int val[maxn];
int n,m;
int chacheng(Point x,Point y)
{
return x.x*y.y-y.x*x.y;
}
bool count(Point i,Point j,Point k)
{
Point x,y;
x.x=(k.x-i.x);
x.y=(k.y-i.y);
y.x=(k.x-j.x);
y.y=(k.y-j.y);
if (chacheng(x,y)<=0) return true;
return false;
// if ((double)(k.y-j.y)/(double)(k.x-j.x)<(double)(j.y-i.y)/(double)(j.x-i.x)) return true;
//return false;
}
void push(Point x)
{
q[++tail]=x;
}
void pop(int lim)
{
}
signed main()
{
while (scanf("%lld%lld",&n,&m)!=EOF)
{
memset(q,0,sizeof(q));
memset(dp,0,sizeof(dp));
memset(sum,0,sizeof(sum));
for (int i=1;i<=n;i++) sum[i]=sum[i-1]+val[i];
dp[0]=0;
push((Point){0,0});
for (int i=1;i<=n;i++)
{
pop(2ll*sum[i]);