编程介的小学生 2020-01-07 00:59 采纳率: 20.5%
浏览 65

Heroes of Might and Magic 的实现

Problem Description
After a very long journey and uncountable number of uphill battles, hero Raelag (who is the transformed Agrael, notice that "Raelag" is an anagram of "Agrael") finally find the map shows where the "Holy Cap" is. Now he is going to find the treasure.

The map is made up of squares of equal size which are arranged in r rows and c columns. At the beginning, Raelag is at the square Labeled 'S', and the "Holy Cap" is at the square Labeled 'T'. It is guarranteed that there is only one 'S' and only one 'T' in a map. Squares that labeled with '#' in the map means squares that can't be passed; '.' means roads that can be passed without any physical loss and squares that labeled with an integer i (1 ≤ i ≤ 9) means when Raelag pass through this square, he will suffer i points of physical loss. Squares that labeled with capital letter 'A', 'B', 'C', 'D' or 'E' means doors that can be passed only if Raelag has the right key (There are at most 5 kinds of doors in a map). The squares labeled with 'S', 'T' and other capital letters all can be passed with out physical loss. Raelag can move to squares only if that square share an edge with the square he is now in. Raelag can't move out of the map.

Input
The fist line of input file contains a single integer T (1 ≤ T ≤ 10) - the number of test cases. For each test case, in the first line their are three integers: r, c and k (1 ≤ r, c ≤ 50, 0 ≤ k ≤ 5), representing the hight, length of the map and the number of kinds of doors in the map. Then there are r lines giving the map. Then k lines follows giving the position of the keys to the door 'A', 'B', 'C', 'D', and 'E' in order.

The uperleft conner is row 1 and colomn 1.

Output
For each test case, output a single integer: the minimum points of physical lose Raelag needs to suffer to find the "Holy Cup". If he can't find the "Holy Cap" any way, output "-1".

Sample Input
2
3 3 1
S21
#A#
11T
1 3
3 5 2
S..A.
##.##
.B.AT
3 1
1 5

Sample Output
6
-1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 vmware exsi重置后登不上
    • ¥15 易盾点选的cb参数怎么解啊
    • ¥15 MATLAB运行显示错误,如何解决?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容
    • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
    • ¥20 yolov5自定义Prune报错,如何解决?
    • ¥15 电磁场的matlab仿真
    • ¥15 mars2d在vue3中的引入问题
    • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面