Problem Description
During the process of the military exercise, there is a ship on the sea level .The ship will go to certain place to carry out a task. For every action, the ship has two ways to sail. They are normal sailing and accelerated sailing. The normal speed of the ship is certain, when the ship sails normally, it can only move 1 step to the adjacent normal sea level. The ship can also accelerate. There are 2 kinds of accelerated sailings, one is moving forward d steps (d <= 5) in a straight line, and it must move forward d steps exactly every time it accelerates, The d steps must be on the normal sea level, otherwise, it can not accelerate. The other is accelerating while getting through the undercurrent. There are a lot of undercurrents on the sea, and entering the undercurrent area needs to accelerate when the ship is 1 step to the undercurrent. However, the ship itself will be damaged more or less by the undercurrent, After entering the undercurrent, the speed of the ship will become normal immediately. Every time it accelerates, the ship has to consume a certain B energy, and when it starts up ,it carries certain B energy.

While the ship is sailing on the sea, it needs to consume a certain A energy. One unit of distance will consume one unit of A energy, and when the ship starts up, it carries enough A energy.

There are many reefs on the sea, and the ship can not get through.

Now the ship is required to sail to the certain place, of course, to minimize the damage to the ship itself is a priority because the cost of ships is very expensive. The damage is, of course, the smaller, the better. At the same time, an attempt should be made to control the consumption of A energy to the smallest amount during the whole process because the cost of A energy is much more expensive than that of B energy, and you can use B energy which the ship carried when it started up as you wish.

Now the question is to work out the minimal times of action from the departure point to the destination under the condition that to minimize the damage to the ship is a priority and then the consumption of A energy to the smallest degree.

Input
The input file contains several test cases, the first line contains an integer T, indicates the number of test cases. In each case the first line includes two integers n, m (5 <= n, m <= 20), which indicate the size of the sea level for military exercises, and n rows and m columns are the current state of the sea level ('S' indicates the ship's initial position, 'E' indicates the destination place, '#' indicates the reefs, '*' indicates the undercurrent , ' ' the normal sea level), followed a line with a number d in it, it indicates the distance of the first kind of acceleration, then another line includes two integers, indicate that the initial value of the B energy and the value of the B energy needed while accelerating every time.

Output
Output an integer to indicate the smallest times of action, and if can not reach the task place, then output "can not reach!"

Sample Input
2
5 10
##########
#E #
#*###### #
#S #
##########
5
10 2
6 10
##########
#E #
#*######*#
#*######*#
#S #
##########
5
3 2

Sample Output
8
can not reach!

• 写回答

#### 1条回答默认 最新

• threenewbee 2017-11-27 15:52
关注
本回答被题主选为最佳回答 , 对您是否有帮助呢?
评论

#### 悬赏问题

• ¥115 不能成功安装R语言pathview包
• ¥15 LEfSe在线分析Galaxy报错，如何解决？
• ¥15 GTEx数据库eqtl数据整理求教学
• ¥20 AI自瞄 KMBOXNET
• ¥15 初学者，自己写的js俄罗斯代码，谁能帮我调试并找出问题所在！！ 自己调试了好多遍！快乱了，崩溃了！
• ¥15 IEC61850库中IedServer_setControlHandler函数的作用
• ¥15 qt 编译webengine 支持 webgl