3892: [Usaco2014 Dec]Marathon

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 169  Solved: 100
[Submit][Status][Discuss]

Description

Unhappy with the poor health of his cows, Farmer John enrolls them in an assortment of different physical fitness activities. His prize cow Bessie is enrolled in a running class, where she is eventually expected to run a marathon through the downtown area of the city near Farmer John's farm! The marathon course consists of N checkpoints (3 <= N <= 500) to be visited in sequence, where checkpoint 1 is the starting location and checkpoint N is the finish. Bessie is supposed to visit all of these checkpoints one by one, but being the lazy cow she is, she decides that she will skip up to K checkpoints (K < N) in order to shorten her total journey. She cannot skip checkpoints 1 or N, however, since that would be too noticeable. Please help Bessie find the minimum distance that she has to run if she can skip up to K checkpoints. Since the course is set in a downtown area with a grid of streets, the distance between two checkpoints at locations (x1, y1) and (x2, y2) is given by |x1-x2| + |y1-y2|.

在二维平面上有N个点,从(x1,y1)到(x2,y2)的代价为|x1-x2|+|y1-y2|。
求从1号点出发,按从1到N的顺序依次到达每个点的最小总代价。
你有K次机会可以跳过某个点,不允许跳过1号点或N号点。

Input

The first line gives the values of N and K. The next N lines each contain two space-separated integers, x and y, representing a checkpoint (-1000 <= x <= 1000, -1000 <= y <= 1000). The checkpoints are given in the order that they must be visited. Note that the course might cross over itself several times, with several checkpoints occurring at the same physical location. When Bessie skips such a checkpoint, she only skips one instance of the checkpoint -- she does not skip every checkpoint occurring at the same location.

Output

Output the minimum distance that Bessie can run by skipping up to K checkpoints. In the sample case shown here, skipping the checkpoints at (8, 3) and (10, -5) leads to the minimum total distance of 4.

Sample Input

5 2
0 0
8 3
1 1
10 -5
2 2

Sample Output

4

HINT

 

Source

Silver

题解:一道神奇的DP,b[i,j]代表从1到i,共计跳跃了j次不难得出递推式

\(b[i,j]=min(b[i-k-1,j-k]+dis(i-k-1,i))\)

,然后\(O\left(N{M}^{2} \right)\)瞎搞万事

 /**************************************************************
Problem:
User: HansBug
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ var
i,j,k,l,m,n:longint;
a:array[..,..] of longint;
b:array[..,..] of longint;
function dis(x,y:longint):longint;inline;
begin
exit(abs(a[x,]-a[y,])+abs(a[x,]-a[y,]));
end;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
begin
readln(n,m);
for i:= to n do readln(a[i,],a[i,]);
fillchar(b,sizeof(b),-);
b[,]:=;
for i:= to n do
begin
for j:= to min(i-,m) do
begin
b[i,j]:=maxlongint;
for k:= to j do
if b[i-k-,j-k]<>- then
begin
b[i,j]:=min(b[i,j],b[i-k-,j-k]+dis(i-k-,i));
end;
end;
end;
writeln(b[n,min(n-,m)]);
end.

3892: [Usaco2014 Dec]Marathon的更多相关文章

  1. bzoj3892[Usaco2014 Dec]Marathon*

    bzoj3892[Usaco2014 Dec]Marathon 题意: 在二维平面上有N个点,从(x1,y1)到(x2,y2)的代价为|x1-x2|+|y1-y2|.求从1号点出发,按从1到N的顺序依 ...

  2. 3893: [Usaco2014 Dec]Cow Jog

    3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 174  Solved: 87[Submit] ...

  3. 3891: [Usaco2014 Dec]Piggy Back

    3891: [Usaco2014 Dec]Piggy Back Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 116  Solved: 92[Subm ...

  4. [bzoj3893][Usaco2014 Dec]Cow Jog_暴力

    Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...

  5. bzoj3891[Usaco2014 Dec]Piggy Back*

    bzoj3891[Usaco2014 Dec]Piggy Back 题意: 给定一个N个点M条边的无向图,其中Bessie在1号点,Elsie在2号点,它们的目的地为N号点.Bessie每经过一条边需 ...

  6. Bzoj3893 [Usaco2014 Dec]Cow Jog

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 302  Solved: 157 Description The cows are out exerci ...

  7. BZOJ3825 : [Usaco2014 Nov]Marathon

    不跳过任何点的路程=dis(l,l+1)+dis(l+1,l+2)+...+dis(r-2,r-1)+dis(r-1,r) 要跳过一个点i,则要最小化dis(i,i+2)-dis(i,i+1)-dis ...

  8. bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】

    设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...

  9. BZOJ-USACO被虐记

    bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...

随机推荐

  1. 从php到浏览器的缓存机制,不得不看!

    所有的php程序员都知道在php脚本里面执行 echo "1";访客的浏览器里面就会显示"1". 但是我们执行下面的代码的时候,并不是显示"1&quo ...

  2. MyBatis绑定错误--BindingException:Invalid bound statement (not found)

    如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...

  3. secache 详解

    介绍下secache缓存,它是属于文件缓存.简单来说,文件缓存就是把缓存数据存储到文件系统 (硬盘)中了,比 内存缓存要慢一些,但是也是有一点优点的. 1.磁盘容量大, 2保存到硬盘,说明 掉电后数据 ...

  4. 分享一些免费的MD5解密网站

    最近下载了几个mdb文件,里面几万条md5和几千条sha512(居然还有站长用512直接放在库中的,尼玛多占空间啊),我用C#写了个工具暴 力了一小部分,大概不到3%吧, 花了我两天,电脑卡得要死,效 ...

  5. Mac系统安装Aircrack-ng破解附近wifi密码(1)

    第一步, 安装macport, 安装Xcode 安装macport macport 是一个工具 管理软件包的一个工具, 我们也可以通过别的方式安装Aircrack-ng, 但是通过macport安装A ...

  6. [2017.02.04] C++学习记录(1)

    编编程语言的目的是帮助程序员以代码的形式表述ideas.编程语言一方面为程序员提供一组关于可以做什么的抽象,另一方面为程序员提供可以被机器执行的轮子.C++编程语言,支持4种编程范式:过程式(Proc ...

  7. 【java设计模式】之 建造者(Builder)模式

    我们还是举上一节的例子:生产汽车.上一节我们通过模板方法模式控制汽车跑起来的动作,那么需求是无止境的,现在如果老板又增加了额外的需求:汽车启动.停止.鸣笛引擎声都由客户自己控制,他想要什么顺序就什么顺 ...

  8. PROC UNIVARIATE过程

    EDA(探索性数据分析)最常用的过程步之一就是PROC UNIVARIATE. 首先先看一个最简单的PROC UNIVARIATE程序: PROC UNIVARIATE DATA=SASHELP.FI ...

  9. 导入AS项目出现类文件全部报红色J 原因

    大家可能遇到过这么一个问题  就是用androidStudio 导入一个新的demo的时候会出现下图的字样 看了是不是很懵逼 我当时看了也是一脸懵逼 这是什么玩意啊.也不报错.也不提示哪里错了 后来我 ...

  10. linux文本处理常用指令总结

    引子 作为一个偏爱windows的程序员,以前做文本处理的时候总是喜欢在windows下用notepad++等图形化工具处理,比如有时需要把linux服务器上一个文件进行一次全局字符串替换这样简单的操 ...