3892: [Usaco2014 Dec]Marathon
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|.
Input
Output
Sample Input
0 0
8 3
1 1
10 -5
2 2
Sample Output
HINT
Source
题解:一道神奇的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的更多相关文章
- bzoj3892[Usaco2014 Dec]Marathon*
bzoj3892[Usaco2014 Dec]Marathon 题意: 在二维平面上有N个点,从(x1,y1)到(x2,y2)的代价为|x1-x2|+|y1-y2|.求从1号点出发,按从1到N的顺序依 ...
- 3893: [Usaco2014 Dec]Cow Jog
3893: [Usaco2014 Dec]Cow Jog Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 174 Solved: 87[Submit] ...
- 3891: [Usaco2014 Dec]Piggy Back
3891: [Usaco2014 Dec]Piggy Back Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 116 Solved: 92[Subm ...
- [bzoj3893][Usaco2014 Dec]Cow Jog_暴力
Cow Jog bzoj-3893 Usaco-2014 Dec 题目大意:题目链接. 注释:略. 想法: 先按照坐标排序. 我们发现每个牛只会被后面的牛影响. 所以我们考虑逆向枚举. 记录一下i+1 ...
- bzoj3891[Usaco2014 Dec]Piggy Back*
bzoj3891[Usaco2014 Dec]Piggy Back 题意: 给定一个N个点M条边的无向图,其中Bessie在1号点,Elsie在2号点,它们的目的地为N号点.Bessie每经过一条边需 ...
- Bzoj3893 [Usaco2014 Dec]Cow Jog
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 302 Solved: 157 Description The cows are out exerci ...
- 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 ...
- bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】
设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...
- BZOJ-USACO被虐记
bzoj上的usaco题目还是很好的(我被虐的很惨. 有必要总结整理一下. 1592: [Usaco2008 Feb]Making the Grade 路面修整 一开始没有想到离散化.然后离散化之后就 ...
随机推荐
- 在Winfrom下实现类似百度、Google搜索自能提示功能
前记:数据源来自页面的一个ComboBox的数据源List<Contract>集合 页面放置一个TextBox(搜索框).ListBox(显示搜索出来的数据),ListBox位置位于Tex ...
- jqGrid Demos
http://www.trirand.com/blog/jqgrid/jqgrid.html http://www.cnblogs.com/huozhicheng/archive/2012/11/11 ...
- HTML5 & CSS3初学者指南(3) – HTML5新特性
介绍 本文介绍了 HTML5 的一些新特性.主要包含以下几个方面: Web 存储 地理位置 拖放 服务器发送事件 Web存储 HTML5 Web 存储的设计与构想是一个更好的机制来存储客户端的网络数据 ...
- Spark工作机制简述
Spark工作机制 主要模块 调度与任务分配 I/O模块 通信控制模块 容错模块 Shuffle模块 调度层次 应用 作业 Stage Task 调度算法 FIFO FAIR(公平调度) Spark应 ...
- 常用的JQ函数
/// <reference path="jquery-1.8.0.min.js"> /* * DIV或元素居中 * @return */ jQuery.fn.mCen ...
- [html5] 学习笔记-改良的input元素种类
在html5中,大幅度增加与改良了input元素的种类,可以简单的使用这些元素来实现之前需要JS脚本来实现的功能. 1.url类型.email类型.date类型.time类型.datetime类型.d ...
- 有趣的++i和i++
作为一个天天和代码“约会”的人来说i++和++i这玩意再熟悉不过了,因为使用频率太高了. 虽然如此,但也未必见得我们真的了解她,不妨猜猜下面的输出结果. #inlcude <stdio.h> ...
- Professional C# 6 and .NET Core 1.0 - 37 ADO.NET
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 37 ADO.NET -------- ...
- java打包jar,war,ear包的作用、区别
java的打包jar,war,ear包的作用,区别,打包方式. a) 作用与区别 i. jar: 通常是开发时要引用通用(JAVA)类,打成包便于存放管理 ii. war ...
- [python]什么是生成器
看理论硬是看的抓狂,然后去百度贴吧看到了一句话,什么叫python生成器,简直秒懂