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

  1. 13 4
  2. 0
  3. 1
  4. 0
  5. 2
  6. 4
  7. 6
  8. 8
  9. 6
  10. 8
  11. 8
  12. 9
  13. 11
  14. 12

Sample Output 1

  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[];
  5. int dp[];
  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=;i<=n;i++) {
  15. scanf("%lf",&a[i]);
  16. dp[i]=inf;
  17. }
  18. dp[]=;
  19. for(int i=;i<=n;i++) {
  20. double mink=1e100;
  21. for(int j=i-;j>=max(i-k,);j--) {
  22. double tmpk=work(i,j,a[i],a[j]);
  23. if(tmpk<=mink) {
  24. dp[i]=min(dp[i],dp[j]+);
  25. mink=tmpk;
  26. }
  27. }
  28. }
  29. printf("%d\n",dp[n]);
  30. }
  31. }

BZOJ1721 Ski Lift 缆车支柱的更多相关文章

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

    Description Farmer Ron in Colorado is building a ski resort for his cows (though budget constraints ...

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

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

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

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

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. POJ2375 Cow Ski Area (强连通)(缩点)

                                        Cow Ski Area Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. D - Cow Ski Area

    Description Farmer John's cousin, Farmer Ron, who lives in the mountains of Colorado, has recently t ...

  7. POJ 2375 Cow Ski Area

    Cow Ski Area Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ...

  8. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  9. 【USACO2006 Mar】滑雪缆车 skilift

    [USACO2006 Mar] 滑雪缆车 skilift Time Limit 1000 msMemory Limit 131072 KBytes Description 科罗拉多州的罗恩打算为奶牛建 ...

随机推荐

  1. 14-敌兵布阵(HDU1166线段树 & 树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=1166 敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. poi导出excel表格

    package poiexcel; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; ...

  3. ubuntu14.04安装chromium以及flash插件

    之前找了好几个方法都不还用,今天突然发现,还挺简单的.命令如下: sudo apt-get updatesudo apt-get install chromium-browser#sudo add-a ...

  4. CSS块级元素、内联元素概念[转]

    CSS文档流与块级元素(block).内联元素(inline),之前翻阅不少书籍,看过不少文章, 看到所多的是零碎的CSS布局基本知识,比较表面.看过O'Reilly的<CSS权威指南>, ...

  5. Luogu 4725 【模板】多项式对数函数

    继续补全模板. 要求 $$g(x) = ln f(x)$$ 两边求导, $$g'(x) = \frac{f'(x)}{f(x)}$$ 然后左转去把多项式求导和多项式求逆的模板复制过来,就可以计算出$g ...

  6. mysql varchar 类型 超出字符

    4.0版本以下,varchar(50),指的是50字节,如果存放UTF8汉字时,只能存16个(每个汉字3字节) 5.0版本以上,varchar(50),指的是50字符,无论存放的是数字.字母还是UTF ...

  7. spring加载ApplicationContext.xml的四种方式

    spring 中加载xml配置文件的方式,好像有4种, xml是最常见的spring 应用系统配置源.Spring中的几种容器都支持使用xml装配bean,包括: XmlBeanFactory , C ...

  8. CentOS7安装redis,并设置开机自启动

    卸载redis 停止并删除所有已的rendis目录即可. rm -rf /home/wls/soft/redis-4.0.2 rm -rf /etc/redis* rm -rf /var/log/re ...

  9. Web测试实践-任务进度-Day03

    小组成员 华同学.郭同学.覃同学.刘同学.穆同学.沈同学 任务进度 在经过任务分配阶段后,大家都投入到了各自的任务中,以下是大家今天任务的进度情况汇总. 华同学 & 刘同学(任务1) 1.再对 ...

  10. python report中文显示乱码

    环境:python2.7 测试框架: nose (1.3.7) nose-html-reporting (0.2.3) 问题:生成测试报告失败的时候,报告会抓取代码中的print,打开后看到的中文是乱 ...