bzoj 4518
思路:
斜率优化;
代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 3005
#define ll long long
ll s[maxn],q[maxn],f[maxn][maxn];
bool getx(int i,int x1,int x2,int x3)
{
return (-s[x2]*s[x2]-f[i-][x2]+s[x1]*s[x1]+f[i-][x1])*
(*s[x2]-*s[x3])>(-s[x3]*s[x3]-f[i-][x3]+s[x2]*s[x2]+
f[i-][x2])*(*s[x1]-*s[x2]);
}
ll getans(int i,int v,int k)
{
return -*s[v]*s[k]+s[k]*s[k]+f[i-][k]+s[v]*s[v];
}
int main()
{
int n,m;scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%lld",&s[i]),s[i]+=s[i-];
memset(f,,sizeof(f)),f[][]=;
for(int i=;i<=m;i++)
{
int head=,tail=;
for(int v=;v<=n;v++)
{
while(head+<=tail&&getx(i,q[tail-],q[tail-],q[tail]))
q[tail-]=q[tail],tail--;
while(head<tail&&getans(i,v,q[head])>=getans(i,v,q[head+])) head++;
f[i][v]=getans(i,v,q[head]),q[++tail]=v;
}
}
printf("%lld\n",f[m][n]*m-s[n]*s[n]);
return ;
}
bzoj 4518的更多相关文章
- 动态规划(决策单调优化):BZOJ 4518 [Sdoi2016]征途
4518: [Sdoi2016]征途 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 532 Solved: 337[Submit][Status][ ...
- BZOJ 4518 [Sdoi2016]征途(分治DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4518 [题目大意] 给出一个数列,分成m段,求方差最小,答案乘上m的平方. [题解] ...
- BZOJ 4518: [Sdoi2016]征途 [斜率优化DP]
4518: [Sdoi2016]征途 题意:\(n\le 3000\)个数分成m组,一组的和为一个数,求最小方差\(*m^2\) DP方程随便写\(f[i][j]=min\{f[k][j-1]+(s[ ...
- ●BZOJ 4518 [Sdoi2016]征途
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4518 题解: 斜率优化DP 首先看看最后答案的形式: 设a[i]为第i天走的距离,那么 $A ...
- 【题解】征途 SDOI 2016 BZOJ 4518
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4518 首先推式子,我们用$x_i$表示第$i$段的路程,$sum$表示总路程,根据方差和平均 ...
- 征途 bzoj 4518
征途(1s 256MB)journey [问题描述] Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天 ...
- BZOJ 4518 征途
斜率优化.又是变量名打错看了老半天. 把方差式子展开一下就好了. #include<iostream> #include<cstdio> #include<cstring ...
- 【BZOJ 4518】【SDOI 2016 Round1 Day2 T3】征途
比较明显的斜率优化DP,省选时因为时间太紧张和斜率DP写得不熟等原因只写了60分的暴力DP,其实当时完全可以对拍来检验标算的正确,但是我当时too naive- 很快打完了,调了将近一晚上QAQ,因为 ...
- bzoj 4518: [Sdoi2016]征途
Description Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜 ...
随机推荐
- Codeforces 937.D Sleepy Game
D. Sleepy Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- poj3613Cow Relays
Cow Relays Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7683 Accepted: 3017 Descri ...
- Problem D. Country Meow 2018ICPC南京
n个点求出最小圆覆盖所有点 退火算法不会,不过这题可以用三分套三分写 x轴y轴z轴各三分 #include <cstdio> #include <cstring> #inclu ...
- Qt ------ 判断运行在何种系统下
#ifdef Q_OS_WIN // Windows上的代码 #endif #ifdef Q_OS_LINUX // Linux上的代码 #endif #ifdef Q_OS_MAC // Mac上的 ...
- mysql5.7中root密码忘记后修改密码
一.更改my.cnf配置文件 1.用命令编辑/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf 2.在[mysqld]下添加skip-grant-t ...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
请检查你在web.xml中加载spring.xml文件的时候没有加载成功,看你的路径是否正确 <context-param> <param-name>contextConfi ...
- [吴恩达机器学习笔记]11机器学习系统设计3-4/查全率/查准率/F1分数
11. 机器学习系统的设计 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考资料 斯坦福大学 2014 机器学习教程中文笔记 by 黄海广 11.3 偏斜类的误差度量 Error Metr ...
- Error : getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
环境 阿里云 centos7 node v8.11.3 npm 5.6.0 错误 npm update 解决 ping registry.npmjs.org 发现https://registry.np ...
- Fire Net(深度优先搜索)
ZOJ Problem Set - 1002 Fire Net Time Limit: 2 Seconds Memory Limit: 65536 KB Suppose that we ha ...
- Elasticsearch技术解析与实战(七)Elasticsearch partial update
普通的partial update 1.插入测试数据 PUT /test_index/test_type/10 { "test_field1": "test1" ...