P3133 [USACO16JAN] Radio Contact G 无线电通话

题目传送门

[USACO16JAN] Radio Contact G

题目描述

Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! They both fan out and search the farm along different paths, but stay in contact via radio so they can keep in touch with each-other. Unfortunately, the batteries in their radios are running low, so they want to plan their movements so as to conserve power, by trying to stay always within a short distance apart.

Farmer John starts at location (\(f_x, f_y\)) and plans to follow a path consisting of \(N\) steps, each of which is either 'N' (north), 'E' (east), 'S' (south), or 'W' west. Bessie starts at location (\(b_x, b_y\)) and follows a similar path consisting of \(M\) steps. Both paths may share points in common. At each time step, Farmer John can either stay put at his current location, or take one step forward along his path, in whichever direction happens to be next (assuming he has not yet reached the final location in his path). Bessie can make a similar choice. At each time step (excluding the first step where they start at their initial locations), their radios consume energy equal to the square of the distance between them.

Please help FJ and Bessie plan a joint movement strategy that will minimize the total amount of energy consumed up to and including the final step where both of them first reach the final locations on their respective paths.

FJ失去了他最喜欢的牛铃,而Bessie已经同意帮助他找到它!他们用不同的路径搜索农场,通过无线电保持联系。不幸的是,无线电中的电池电量不足,所以他们设法尽可能保持两者位置的距离最小,以节省电量。

FJ从位置(fx,fy)开始,并计划遵循由N步骤组成的路径,每个步骤都是“N”(北),“E”(东),“S”(南),或“W”(西)。Bessie从位置(bx,by)开始,并遵循由M步骤组成的类似路径。两个路径可以经过相同的点。在每个时间段,FJ可以保持在他现在的位置,或沿着他的道路前进一步,无论哪个方向恰好在下一个(假设他还没有到达他的路径的最后位置)。Bessie可以做出类似的选择。在每个时间步(不包括从初始位置开始的第一步),他们的无线电消耗的能量等于它们之间距离的平方。

请帮助FJ和Bessie计划行动策略,最大限度地减少消耗的能量总量。总量包括最终步骤,这时两者首先到达各自路径上的最终位置。

输入格式

The first line of input contains \(N\) and \(M\) (\(1 \leq N, M \leq 1000\)). The

second line contains integers \(f_x\) and \(f_y\), and the third line contains \(b_x\)

and \(b_y\) (\(0 \leq f_x, f_y, b_x, b_y \leq 1000\)). The next line contains a

string of length \(N\) describing FJ's path, and the final line contains a string

of length \(M\) describing Bessie's path.

It is guranteed that Farmer John and Bessie's coordinates are always in the

range (\(0 \leq x,y \leq 1000\)) throughout their journey. Note that East points in the positive x direction and North points in the positive y direction.

第一行输入N和M(1≤N,M≤1000)。

第二行输入整数fx和fy,第三行输入bx和by(0≤fx,fy,bx,≤1000)。下一行包含一个长度为N的字符串描述FJ的路径,最后一行包含一个字符串的长度M描述Bessie的路径。

数据满足(0≤x,y≤1000)。注意,东方向为正X方向,北方向为正Y方向。

输出格式

Output a single integer specifying the minimum energy FJ and Bessie can use

during their travels.

输出一个整数,表示最小能量。

样例 #1

样例输入 #1

2 7
3 0
5 0
NN
NWWWWWN

样例输出 #1

28

提示

感谢@ prcups 改进翻译

思路

先分别求出农夫和奶牛没走一步到达的点

设 \(dp_{i , j}\) 当农夫走了 \(i\) 步,奶牛走了 \(j\) 步后的最小花费

那么

\[dp_{i , j} = min (dp_{i - 1 , j} , min (dp _{i , j - 1 } , dp _{i - 1 , j - 1 })) +dis(i , j)
\]

注意判断越界条件,\(dp_{0 , 0} = 0\)

后记

考试时 \(dis\) 打错了,差点就寄了。

P3133 [USACO16JAN] Radio Contact G 无线电通话的更多相关文章

  1. 洛谷 P3133 [USACO16JAN]Radio Contact G

    题目传送门 解题思路: f[i][j]表示FJ走了i步,Bessie走了j步的最小消耗值.方程比较好推. 横纵坐标要搞清楚,因为这东西WA了半小时. AC代码: #include<iostrea ...

  2. 洛谷 P3133 [USACO16JAN]无线电联系Radio Contact

    P3133 [USACO16JAN]无线电联系Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the ...

  3. 「BZOJ4510」「Usaco2016 Jan」Radio Contact 解题报告

    无线电联系 Radio Contact 题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed t ...

  4. P3133 [USACO16JAN]无线电联系Radio Contact

    题目描述 Farmer John has lost his favorite cow bell, and Bessie the cow has agreed to help him find it! ...

  5. [USACO16JAN]Angry Cows G 解题报告

    一图流 参考代码: #include<bits/stdc++.h> #define ll long long #define db double #define filein(a) fre ...

  6. 越狱Season 1-Episode 7: Riots, Drills and the Devil: Part 2

    Season 1, Episode 7: Riots, Drills and the Devil: Part 2 -Pope: Belick, get those guys in line guy: ...

  7. VCF文件导入导出

    参考资料 通讯录导入导出vcf格式文件方法可参考: https://qiaodahai.com/android-iphone-mobile-phones-contacts-import-and-exp ...

  8. [SinGuLaRiTy] 2017-07-21 综合性测试

    [SinGuLaRiTy-1028] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 对于所有题目:Time Limit: 1s | Memo ...

  9. bzoj AC倒序

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

  10. BlackArch-Tools

    BlackArch-Tools 简介 安装在ArchLinux之上添加存储库从blackarch存储库安装工具替代安装方法BlackArch Linux Complete Tools List 简介 ...

随机推荐

  1. [数据库]mysql/mysqldump命令帮助说明

    1 mysql [root@test ~]# mysql --help mysql Ver 14.14 Distrib 5.7.24-27, for Linux (x86_64) using 6.0 ...

  2. 一道名题-(csp 儒略日)的心得与技巧

    引: 如果你见到一个oi对着 4713,1582 146097 2299160 颠颠地笑,不用怀疑,他是在做那道名题--<csp-s2020 T1 儒略日> 这道题,我做了三年,平均每年做 ...

  3. 51nod 1153 选择子序列

    51nod 选择子序列 这道题是\(Bunny\)学长在给我们的模拟赛中的一道题. 食用单调栈,处理每个数\(a_i\)左右第一个比自己大的数的下标\(left_i\),\(right_i\),并且建 ...

  4. DG:模拟failover故障与恢复

    问题描述:情形是当主库真正出现异常之后,才会执行的操作,那么我们执行过failover 之后,如何在重新构建DG,这里我们利用flashback database来重构.模拟前主库要开启闪回区,否则要 ...

  5. 注解:@RequiredArgsConstructor、 @Validated、 @Valid、 @Lazy

    1. lombok注解:@RequiredArgsConstructor Spring 依赖注入方式 1.通过 @Autowire.@Resource 等注解注入, 2.通过构造器的方式进行依赖注入. ...

  6. 省选联考2021vp记

    卡牌游戏 考虑到将 \(a\) 和 \(b\) 放在一起排序,最后朝上的数字必然在左端点为最小值,右端点为最大值的区间中.这个区间中至少有 \(n-m\) 个是原来的 \(a\),且对于每张卡牌必然要 ...

  7. C++ Primer 5th Edition, Chapter 2, Solutions

    Exercise 2.1 Questions What are the differences between int, long, long long, and short? Between an ...

  8. vscode使用git推送代码

    下载vscode https://code.visualstudio.com/ 点击应用管理 搜素Chinese (Simplified) Language Pack for Visual Studi ...

  9. Prism Sample 16-RegionContext

    终于发现一个有趣的新知识了. 本例的核心是RegionContext,意思是一个区域的上下文.但与DataContext似乎并不相同. 先看一下整体思路. 在主窗体上只有一个Region: <G ...

  10. selenium控制文件下载位置

    selenium控制文件下载位置 我们在自动化下载文件的时候势必存在一种需求: 通过chrome将文件保存到指定位置 1. google窗口实现 ​ 配置'prefs'将文件下载到指定位置, 并通过判 ...