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 路面修整 一开始没有想到离散化.然后离散化之后就 ...
随机推荐
- Spark算子总结及案例
spark算子大致上可分三大类算子: 1.Value数据类型的Transformation算子,这种变换不触发提交作业,针对处理的数据项是Value型的数据. 2.Key-Value数据类型的Tran ...
- 关于多字节字符入库失败处理(所谓的Emji),该处理是舍弃特殊字符
具体处理方法及样例如下: /** * 屏蔽超过三个字节以上的字符 * @param strByte * @return */ public static String filterUtf8(byte[ ...
- android:在ViewPager中使用Button
最近在项目用用到ViewPager ,其中页面包含有Button,因为之前也有使用个ViewPager ,所以这个也照搬之前的方式,测试后发现点击button无法执行,这个button是在第一页面的默 ...
- Spring集成MyBatis框架
Java在写数据库查询时,我接触过四种方式: 1.纯Java代码,引用对应的数据库驱动包,自己写连接与释放逻辑(可以用连接池) 这种模式实际上性能是非常不错的,但是使用起来并不是非常方便:一是要手工为 ...
- [CSS3]学习笔记-CSS基本样式讲解
1.CSS样式-背景 CSS运行应用纯色作背景,也允许使用背景图像创建相当复杂的效果 <!DOCTYPE html> <html> <head lang="en ...
- Spring + Quartz配置实例
Spring为创建Quartz的Scheduler.Trigger和JobDetail提供了便利的FactoryBean类,以便能够在Spring 容器中享受注入的好处.此外Spring还提供了一些便 ...
- 说说 bash 的 if 语句
说说 bash 的 if 语句 在开始先给大家列出几个术语,不做解释,不懂的可以参考其它资料. 术语和符号: 退出状态码 $? [...] (中括号,方括号) [[...]] (双中括号,双方括号) ...
- 微信小程序image组件binderror使用例子(对应html、js中的onerror)
官方文档 binderror HandleEvent 当错误发生时,发布到 AppService 的事件名,事件对象event.detail = {errMsg: 'something wrong' ...
- matlab 逻辑数组及其应用
这几天学习了matlab的逻辑数组功能,总的感觉就有两点: 第一,通过对原来的数组a进行逻辑判断后得到逻辑数组b 第二,逻辑数组进行某种运算符操作又回到原数组类型 第三,利用逻辑数组mask功能 测试 ...
- dotnet new 命令使用模板
dotnet new 命令使用模板快速生成单页应用. 最新版.NET Core SDK RC4 最大改动是更新了 dotnet new 命令. dotnet new 默认不再创建控制台应用,而是展示帮 ...