CodeForces 674C Levels and Regions
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int N,K,head,tair;
int q[maxn];
double S[maxn],A[maxn],B[maxn],dp[maxn][55];
double calc(int i,int j,int k){return dp[k][j-1]+A[i]-A[k]-S[k]*(B[i]-B[k]);}
double x(int k){return S[k];}
double y(int k,int j){return dp[k][j-1]-A[k]+S[k]*B[k];}
bool judge(int a,int b,int c,int j){return (x(a)-x(c))*(y(a,j)-y(b,j))>=(y(a,j)-y(c,j))*(x(a)-x(b));}
int main()
{
while(~scanf("%d%d",&N,&K))
{
S[0]=A[0]=B[0]=0;
for(int i=1;i<=N;++i)
{
double t;scanf("%lf",&t);
S[i]=S[i-1]+t;
B[i]=B[i-1]+1/t;
A[i]=A[i-1]+S[i]/t;
}
//printf("start\n");
for(int i=1;i<=N;++i)dp[i][1]=A[i];
for(int j=2;j<=K;++j)
{
q[head=tair=1]=j-1;
for(int i=j;i<=N;++i)
{
while(head<tair&&calc(i,j,q[head])>=calc(i,j,q[head+1]))head++;
dp[i][j]=calc(i,j,q[head]);
while(head<tair&&judge(q[tair-1],q[tair],i,j))tair--;
q[++tair]=i;
}
}
printf("%.6f\n",dp[N][K]);
}
}
CodeForces 674C Levels and Regions的更多相关文章
- Codeforces 643C Levels and Regions 斜率优化dp
Levels and Regions 把dp方程列出来, 把所有东西拆成前缀的形式, 就能看出可以斜率优化啦. #include<bits/stdc++.h> #define LL lon ...
- DP的优化总结
一.预备知识 \(tD/eD\) 问题:状态 t 维,决策 e 维.时间复杂度\(O(n^{e+t})\). 四边形不等式: 称代价函数 w 满足凸四边形不等式,当:\(w(a,c)+w(b,d)\l ...
- DP 优化方法大杂烩 & 做题记录 I.
标 * 的是推荐阅读的部分 / 做的题目. 1. 动态 DP(DDP)算法简介 动态动态规划. 以 P4719 为例讲一讲 ddp: 1.1. 树剖解法 如果没有修改操作,那么可以设计出 DP 方案 ...
- Codeforces 526E Transmitting Levels
http://codeforces.com/contest/526/problem/E 题意:给一个环,每个点有权值,每次给一个数B,求把这个环切割成若干部分,每个部分不超过B,至少要切成几块? #i ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #354 (Div. 2)-B
B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...
- Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分
C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...
- Codeforces Beta Round #6 (Div. 2 Only) D. Lizards and Basements 2 dp
题目链接: http://codeforces.com/problemset/problem/6/D D. Lizards and Basements 2 time limit per test2 s ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
随机推荐
- Codeforces Round #628 (Div. 2)
1325A - EhAb AnD gCd 题意:随意找两个数是他们的最大公约数 GCD 与最小公倍数 LCM 之和为所给定的值. 思路:找一下规律 ,假设所给的 数位n, 那么我们将n分成 1 ,n- ...
- oracle实现分页功能 limit功能例子
oracle数据库不支持mysql中limit功能,但可以通过rownum来限制返回的结果集的行数,rownum并不是用户添加的字段,而是oracle系统自动添加的. 记录两种常用方法: (1)使查询 ...
- Elasticsearch7.6学习笔记1 Getting start with Elasticsearch
Elasticsearch7.6学习笔记1 Getting start with Elasticsearch 前言 权威指南中文只有2.x, 但现在es已经到7.6. 就安装最新的来学下. 安装 这里 ...
- php依赖注入与容器,Container,控制反转
依赖注入与Ioc容器 概念: 容器:可以理解为用来存放某个东西的物品(篮子?),存放的东西取决于你想往里面放点什么.在这里,我们是存放某个类,类的描述或者一个返回类实例的闭包函数. Ioc(Inver ...
- 前端面试题解密:经典算法之冒泡算法(ES6版)及优化
前言 随着前端的飞速发展,前端业务开发给前端工程师提出了更高的要求,因而算法题也越来越高频次的出现在前端面试中.有很多的小伙伴找胡哥苦诉,在前端实际开发中(除了涉及游戏开发方面),算法使用有很多吗?大 ...
- 【php】面向对象(二)
一. 封装: a) 描述:使用成员修饰符修饰成员属性和成员方法,能够最大限度的隐藏对象内部的细节,保证对象的安全 b) PPP修饰符:public(公共的),protected(受保护的),priva ...
- Linux如何配制Tcl编程环境
首先,打开终端. 接着在终端输入以下命令: sudo apt-get install tcl
- Linux c++ vim环境搭建系列(1)——Ubuntu18.04.4编译安装vim8.2
1. vim源码编译安装 参考网址: https://github.com/ycm-core/YouCompleteMe/wiki/Building-Vim-from-source 安装各类依赖库 s ...
- ASP.NET Core中配置监听URLs的五种方式
原文: 5 ways to set the URLs for an ASP.NET Core app 作者: Andrew Lock 译者: Lamond Lu 默认情况下,ASP. NET Core ...
- CVPR2020|3D-VID:基于LiDar Video信息的3D目标检测框架
作者:蒋天园 Date:2020-04-18 来源:3D-VID:基于LiDar Video信息的3D目标检测框架|CVPR2020 Brief paper地址:https://arxiv.org/p ...