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

 #include<bits/stdc++.h>
using namespace std; double a[];
int dp[];
const int inf=0x3f3f3f3f;
double work(int x1,int x2,double y1,double y2) {
return (y1-y2)/(x1-x2);
} int main() {
int n,k;
while(~scanf("%d%d",&n,&k)) {
for(int i=;i<=n;i++) {
scanf("%lf",&a[i]);
dp[i]=inf;
}
dp[]=;
for(int i=;i<=n;i++) {
double mink=1e100;
for(int j=i-;j>=max(i-k,);j--) {
double tmpk=work(i,j,a[i],a[j]);
if(tmpk<=mink) {
dp[i]=min(dp[i],dp[j]+);
mink=tmpk;
}
}
}
printf("%d\n",dp[n]);
}
}

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. Linux虚拟机磁盘扩容

    扩容步骤如下: 1.添加一块物理硬盘 2.fdisk将硬盘分区,选primary分区,创建1-4个 3.分区类型格式化,选择t,输入LVM代号 4.分好后按w退出 如果是调整原有逻辑卷大小,则先调整原 ...

  2. tomcat安装后,双击start.bat闪退的问题

    1.jdk环境变量没有配 解决方案:我的电脑-属性-高级-环境变量,新增下面三个环境变量: ①JAVA_HOME=C:\Program Files\Java\jdk1.7.0_09(就是你jdk安装的 ...

  3. Greeplum 系列(三) 基本用法

    Greeplum 系列(三) 基本用法 <PostgreSQL 教程>:https://www.yiibai.com/postgresql 一.Greeplum 登陆与创建 1.1 登陆 ...

  4. Fiddldr 教程之:HTTP协议详解(转)

    原文地址:http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html HTTP协议详解 当今web程序的开发技术真是百家争鸣,ASP ...

  5. css3之transform-origin

    transform-origin属性平时似乎用得很少,它决定了变换时依赖的原点.基本的属性特性可以参考CSS手册. 如果在H5动画项目中,用到旋转的话,它还是不能小觑的. 假如我们做一个秋千效果 其实 ...

  6. CodeForces 289B Polo the Penguin and Matrix (数学,中位数)

    题意:给定 n * m 个数,然后每次只能把其中一个数减少d, 问你能不能最后所有的数相等. 析:很简单么,首先这个矩阵没什么用,用一维的存,然后找那个中位数即可,如果所有的数减去中位数,都能整除d, ...

  7. CodeForces 146E Lucky Subsequence(组合数+DP)

    题目描述 Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers w ...

  8. CodeForces 620E New Year Tree(线段树的骚操作第二弹)

    The New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited h ...

  9. MAX6675操作源码--K型热电偶模数转换器

    #define P_TENB PF4_OUT #define P_TSLK PA3_OUT #define P_TDAT PB2_IN //****************************** ...

  10. Discuz!和jQuery冲突的解决办法

    Common.js是官方自带的,我没改过它,所以不可能出错,所以问题就应该是两者冲突了.导致的结果我也发现了,前台的DIY功能不能用了.   我还花了很多时间在那里研究冲突的地方,后来还是没能解决.之 ...