BNUOJ 26224 Covered Walkway
Covered Walkway
This problem will be judged on HDU. Original ID: 4258
64-bit integer IO format: %I64d Java class name: Main
The building contractor has an interesting pricing scheme. To cover the walkway from a point at x to a point at y, they will charge c+(x-y)2, where c is a constant. Note that it is possible for x=y. If so, then the contractor would simply charge c.
Given the points along the walkway and the constant c, what is the minimum cost to cover the walkway?
Input
Output
Sample Input
10 5000
1
23
45
67
101
124
560
789
990
1019
0 0
Sample Output
30726
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
LL n,c,d[maxn],dp[maxn];
int q[maxn],head,tail;
LL G(int k,int j){
return dp[j] + d[j+]*d[j+] - (dp[k]+d[k+]*d[k+]);
}
LL S(int k,int j){
return (d[j+]-d[k+]);
}
int main(){
int i,j;
while(scanf("%I64d %I64d",&n,&c),(n||c)){
for(i = ; i <= n; i++)
scanf("%I64d",d+i);
dp[] = q[] = ;
head = tail = ;
for(i = ; i <= n; i++){
while(head < tail && G(q[head],q[head+]) <= *d[i]*S(q[head],q[head+])) head++;
dp[i] = dp[q[head]] + (d[i]-d[q[head]+])*(d[i]-d[q[head]+])+c;
while(head < tail && G(q[tail-],q[tail])*S(q[tail],i) >= G(q[tail],i)*S(q[tail-],q[tail])) tail--;
q[++tail] = i;
}
printf("%I64d\n",dp[n]);
}
return ;
}
BNUOJ 26224 Covered Walkway的更多相关文章
- HDU 4258 Covered Walkway 斜率优化DP
Covered Walkway Problem Description Your university wants to build a new walkway, and they want at ...
- hdu 4258 Covered Walkway
题目大意: 一个N个点的序列,要将他们全部覆盖,求总最少费用:费用计算: c+(x-y)2 分析: 斜率优化DP 我们假设k<j<i.如果在j的时候决策要比在k的时候决策好,那么也是就是d ...
- HDU 4258(Covered Walkway-斜率优化)
Covered Walkway Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- ACM - 动态规划专题 题目整理
CodeForces 429B Working out 预处理出从四个顶点到某个位置的最大权值,再枚举相遇点,相遇的时候只有两种情况,取最优解即可. #include<iostream> ...
- HDU 4258 斜率优化dp
Covered Walkway Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- Walkway.js – 用线条制作简约的 SVG 动画
Walkway.js 是一个使用线条和路径元素组成 SVG 动画图像的简单方法.只需根据提供的配置对象创建一个新的 Walkway 实例就可以了.这种效果特别适合那些崇尚简约设计风格的网页.目前, W ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- 备忘:maven 错误信息: Plugin execution not covered by lifecycle configuration
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 【技巧】“Plugin execution not covered by lifecycle configuration...“异常的处理
问题现象: 在Eclipse(JEE mars)中新建maven project,选择archetype为:maven-archetype-plugin,结果生成的project存在错误:“Plugi ...
随机推荐
- SVN报错 Not Found In Revision 不支持空目录
如果你要初始化上传的SVN目录为空,有可能会报这个错误 解决方法:在SVN下新建一个目录即可
- poj Find a multiple【鸽巢原理】
参考:https://www.cnblogs.com/ACShiryu/archive/2011/08/09/poj2356.html 鸽巢原理??? 其实不用map但是习惯了就打的map 以下C-c ...
- 392 Is Subsequence 判断子序列
给定字符串 s 和 t ,判断 s 是否为 t 的子序列.你可以认为 s 和 t 中仅包含英文小写字母.字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=10 ...
- [ SPOJ RESTACK ] Restacking haybales
\(\\\) Description 给出一个环,每个位置有一个初值 \(A_i\),有一个目标值 \(B_i\),保证 \(\sum A_i=\sum B_i\) 每个位置只能把值分给隔壁的,每次分 ...
- 常见Z纯CSS小样式合集(三角形)
三角形 .sanjiao{ width:0px; height: 0px; overflow: hidden; border-width: 100px; border-color: transpare ...
- Android通过微信实现第三方登录并使用OKHttp获得Token及源码下载
这里对于App在微信开放平台上申请AppID和secret在这里就略过了,我们微信的授权登录流程,腾讯官网给的流程如下: 1. 第三方发起微信授权登录请求,微信用户允许授权第三方应用后,微信会拉起应用 ...
- table的数据行tr上下移动
昨天帮别人解决一个前端页面表格里的数据行上下移动的前端效果,直奔google找了几个demo,发现demo是实现了效果,但是代码很多,最后还是决定自己用jquery写个吧, 首先将前端效果分析出编程逻 ...
- iOS从手机相册选择一张照片并显示 Objective-C
要先给app设置访问相册的权限: 在项目的Info.plist文件里添加Privacy - Photo Library Usage Description权限 ViewController.h: #i ...
- java生成excel
package test.poi; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; ...
- 分析器错误消息: 该配置节不能包含 CDATA 或文本元素。
原因当然是web.config配置文件中,有字符串文本了,估计不小心加上的一些字符,所以会报错,去掉就行,例如13行的s