链接

思路

  斜率优化dp。

代码

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath> using namespace std;
typedef long long LL;
int n,L,R;
LL A,B,C,s[],q[],f[]; inline int read() {
int x = ,f = ;char ch = getchar();
for (; !isdigit(ch); ch=getchar()) if(ch=='-') f=-;
for (; isdigit(ch); ch=getchar()) x = x*+ch-'';
return x * f;
}
double Y(int x) {
return double(f[x]+A*s[x]*s[x]-B*s[x]);
}
double slope(int i,int j) {
return (Y(i)-Y(j))/double(s[i]-s[j]);
}
int main() {
n = read(),A = read(),B = read(),C = read();
for (int i=; i<=n; ++i) s[i] = read(),s[i] += s[i-]; int L = ,R = ;
q[++R] = ;
for (int i=; i<=n; ++i) {
while (L<R && slope(q[L],q[L+])>2.0*A*s[i]) L++;
int j = q[L];
f[i] = f[j]+A*(s[i]-s[j])*(s[i]-s[j])+B*(s[i]-s[j])+C;
while (L<R && slope(q[R-],q[R])<slope(q[R],i)) R--;
q[++R] = i;
}
cout << f[n];
return ;
}

最新文章

  1. python迭代器实现斐波拉契求值
  2. ThinkPHP中疑难笔记
  3. 安卓普通类通过classloader访问资源文件
  4. PHP中的位运算与位移运算(其它语言通用)
  5. asp.net identity 2.2.0 中角色启用和基本使用(七)提示点
  6. 微信浏览器——User Agent
  7. 内存不足时Android 系统如何Kill进程
  8. 判断Http请求由手机端发起,还是有电脑端发起
  9. docker导入本地镜像
  10. (转)eclipse报错及解决说明 &quot;XX cannot be resolved to a type &quot;
  11. javascript之BOM编程Screen(屏幕)对象
  12. C/C++预处理指令#define,#ifdef,#ifndef,#endif… (转)
  13. Windows之常用命令
  14. 使用VMware 虚拟linux系统环境
  15. CSS效果:不怎么样的登录表单
  16. 如何解决selenium打开chrome提示chromedriver.exe已停止工作
  17. 第 6 章 —— 依赖项注入(DI)容器 —— Ninject
  18. Java第三阶段学习(一、IO流------File类)
  19. 微信小程序开发7-JavaScript脚本
  20. Superset 初探

热门文章

  1. SharePoint 2010 究竟需要占用多少服务器资源?
  2. struts2.3.4.1转换成eclipse项目的过程
  3. 《最牛B的Linux Shell命令》笔记
  4. 笨办法学Python(二十九)
  5. Django Field lookups (字段查找)
  6. InnoDB锁演示
  7. Javascript Ajax 请求
  8. js中this的运用
  9. JavaServlet 路径书写总结
  10. 一篇SSM框架整合友好的文章(一)