BZOJ1721 Ski Lift 缆车支柱

Description

Farmer Ron in Colorado is building a ski resort for his cows (though budget constraints dictate construction of just one ski lift). The lift will be constructed as a monorail and will connect a concrete support at the starting location to the support at the ending location via some number of intermediate supports, each of height 0 above its land. A straight-line segment of steel connects every pair of adjacent supports. For obvious reasons, each section of straight steel must lie above the ground at all points. Always frugal, FR wants to minimize the number of supports that he must build. He has surveyed the N (2 <= N <= 5,000) equal-sized plots of land the lift will traverse and recorded the integral height H (0 <= H <= 1,000,000,000) of each plot. Safety regulations require FR to build adjacent supports no more than K (1 <= K <= N - 1) units apart. The steel between each pair of supports is rigid and forms a straight line from one support to the next. Help FR compute the smallest number of supports required such that: each segment of steel lies entirely above (or just tangent to) each piece of ground, no two consecutive supports are more than K units apart horizontally, and a support resides both on the first plot of land and on the last plot of land.

科罗拉州的罗恩打算为他的奶牛们建造一个滑雪场,虽然需要的设施仅仅是一部缆车.建造一部缆车,需要从山脚到山顶立若干根柱子,并用钢丝连结它们.你可以认为相对于地面,柱子的高度可以忽略不计.每相邻两根柱子间都有钢丝直接相连.显然,所有钢丝的任何一段都不能在地面之下.    为了节省建造的费用,罗恩希望在工程中修建尽可能少的柱子.他在准备修建缆车的山坡上迭定了N(2≤N≤5000)个两两之间水平距离相等的点,并且测量了每个点的高度H(O≤日≤10^9).并且,按照国家安全标准,相邻两根柱子间的距离不能超过K(1≤K≤N-1)个单位长度.柱子间的钢丝都是笔直的. 罗恩希望你帮他计算一下,在满足下列条件的情况下,他至少要修建多少根柱子:首先,所有的柱子都必须修建在他所选定的点上,且每一段钢丝都必须高于地面或者正好跟地面相切.相邻两根柱子的距离不大于K个单位长度.当然,在第一个点与最后一个点上一定都要修建柱子.

Input

* Line 1: Two space-separate integers, N and K

* Lines 2..N+1: Line i+1 contains a single integer that is the height of plot i.

第1行:两个整数N和K,用空格隔开.

第2到N+1行:每行包括一个正整数,第i+l行的数描述了第i个点的高度.

Output

* Line 1: A single integer equal to the fewest number of lift towers FR needs to build subject to the above constraints

输出一个整数,即罗恩最少需要修建的柱子的数目.

Sample Input 1

13 4
0
1
0
2
4
6
8
6
8
8
9
11
12

Sample Output 1

5

Source

BZOJ-1721

dp[i]表示前i个至少需要修建几根柱子。

图中情况肯定选红色的。所以倒着维护斜率就可以了。

dp[i]=max(dp[i] , dp[j] + 1)  ,  max(1,i-k) <= j <i && 斜率tmpk<=mink

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3
 4 double a[5010];
 5 int dp[5010];
 6 const int inf=0x3f3f3f3f;
 7 double work(int x1,int x2,double y1,double y2) {
 8     return (y1-y2)/(x1-x2);
 9 }
10
11 int main() {
12     int n,k;
13     while(~scanf("%d%d",&n,&k)) {
14         for(int i=1;i<=n;i++) {
15             scanf("%lf",&a[i]);
16             dp[i]=inf;
17         }
18         dp[1]=1;
19         for(int i=2;i<=n;i++) {
20             double mink=1e100;
21             for(int j=i-1;j>=max(i-k,1);j--) {
22                 double tmpk=work(i,j,a[i],a[j]);
23                 if(tmpk<=mink) {
24                     dp[i]=min(dp[i],dp[j]+1);
25                     mink=tmpk;
26                 }
27             }
28         }
29         printf("%d\n",dp[n]);
30     }
31 }

posted @ 2019-04-21 14:34 ACMerszl 阅读(...) 评论(...) 编辑 收藏

BZOJ1721 Ski Lift 缆车支柱相关推荐

  1. [BZOJ1721][Usaco2006 Mar]Ski Lift 缆车支柱

    日常吐槽:最大值赋太大79分卡了好久好久 算法:DP 分析:数学分析一下即可 最优解肯定是介个样子的: 抽象一点的话: 也就是说两个点(i,j)之间如果能够连上线,则必定中间点对(i,k(k∈(i,j ...

  2. 1721: [Usaco2006 Mar]Ski Lift 缆车支柱

    题目链接 题目大意:在山上规划一条缆车线路, 整座山可以用一条折线来描述,该折线有N个拐点,起点是1,终点是N.每个拐点的高度为Hi,相邻两个拐点之间的水平距离都是1 1.相邻支柱的水平距离不能超过K ...

  3. 题解 P4909 【[Usaco2006 Mar]Ski Lift 缆车支柱】

    emmm,这道题我们今天集训的一道题... 思路:怎么搞呢这道题,对于当前点i,我们往后枚举,求得最优值,很明显是个动态规划,但是题中很明显有着一个限制条件,就是说当i要连向j时,我们这条线不能触碰到 ...

  4. luogu 4909 [Usaco2006 Mar]Ski Lift 缆车支柱 动态规划

    可以出模拟赛T1? #include <bits/stdc++.h> #define N 5002 #define inf 1000000 #define setIO(s) freopen ...

  5. BZOJ-1721|线性dp-缆车支柱

    Ski Lift 缆车支柱 Description Farmer Ron in Colorado is building a ski resort for his cows (though budge ...

  6. P4909 Ski Lift G 题解

    题解: 设 d p i dp_i dpi​ 为选取前 i i i 个点且选第 i i i 个点的答案,显然答案为 d p n dp_n dpn​. 考虑转移,转移类似于 n 2 n^2 n2 的最长上 ...

  7. amis eureka_如何构建量身定制的amis来升级您的基础架构

    amis eureka There comes a time in everyone's infrastructure journey that you have to build your own ...

  8. 前端工程师 后段工程师_如何像工程师一样思考

    前端工程师 后段工程师 In my time in the tech field, I have learned that it really doesn't matter what tools or ...

  9. Check It Again:论文整理

    蕴含简介 文本蕴含:文本间的推理关系,又称为文本蕴含关系,作为一种基本的文本间语义联系,广泛存在于自然语言文本中.简单的来说文本蕴含关系描述的是两个文本之间的推理关系,其中一个文本作为前提,另一个文本 ...

最新文章

  1. web.config文件详解
  2. 技术图文:如何利用 Turtle 绘制一棵漂亮的樱花树
  3. Robot 3D Map Navigation
  4. mysql 分库分表 建表_【分库分表】sharding-jdbc实践—分库分表入门
  5. jni 字符串的梳理
  6. WAF Bypass数据库特性(Mysql探索篇)
  7. 在Android中取得当前进程名
  8. php ci框架分页类,nusoap 与 CI框架不用WSDL
  9. 1.解读REST和JAX-RS
  10. 【AI视野·今日Robot 机器人论文速览 第二十五期】Fri, 1 Oct 2021
  11. php把服务器文件curl提交,php中使用curl进行文件上传的巨坑
  12. python画图包-Python 绘图包 Matplotlib Pyplot 教程
  13. 开发者如何钻 App Store 的漏洞?
  14. 速读-高级技能二:并行输入训练
  15. 论文精读—XGBoost paper
  16. 数字电路基础知识(二)
  17. 第一遍C++Primer5th读完感
  18. php与jpython-在python中复数怎么表示
  19. python k线斜率计算_python求线性回归斜率
  20. 网络编程学习路线计划

热门文章

  1. 浅谈GPU虚拟化技术(四)- GPU分片虚拟化
  2. 芒果改进YOLOv7系列:超越ConvNeXt结构,原创结合Conv2Former改进结构,Transformer 风格的卷积网络视觉基线模型,高效涨点
  3. VS2010启动后鼠标失灵解决方法
  4. SpringBoot配置与应用 SpringBoot与(Spring和springmvc的区别)
  5. 7-2 sdust-Java-学生成绩读取与排序 (20 分)
  6. IP防护等级解释说明
  7. Java-汉字字符串转拼音,包括首字母和全拼
  8. 分享111个ASP源码,总有一款适合您
  9. 手机里的OFD文件如何转成PDF
  10. 精神分裂型患者大脑结构和功能连接的改变