Jun garlic rescue

Question:
garlic Jun is a happy boy to help others, the day his village where flooding occurs, there are a number of villagers were trapped on the island, so the garlic king decided to go back they left the woods, where the monarch is assumed that the village garlic is n × mn × m grid, the grid. No. representative of the ground, to which # represents the number has been flooded, a, B ...... capital letters like the local villagers trapped, s Representative starting Jun garlic, t representatives of garlic Jun destination.

The initial velocity is k seconds garlic Jun a grid, a grid every time he can move vertically and horizontally in a four directions. A villager in the back, his speed may be reduced, but also is likely to accelerate, but his speed is not faster than 1 second per frame, then the garlic king wanted to know how long he will be the fastest of all the villagers rescued?

Note: You can not put down the outside of the end of the local villagers; villagers can carry more than at the same time.

The first line of three positive integers n, m (1≤n, m≤10), kn, m (1≤n, m≤10), k, respectively village length, width, garlic Jun initial velocity.

Next nn lines, each line of a string mm, indicative of the terrain, the string meaning as described above village.

The next several lines of a capital letter, one integer representing the number of villagers kk will increase / decrease the number. The number of rows equal to the number of uppercase letters terrain. Capital letters lexicographical ordering, i.e., order A, B, C, to ensure the letters before and after the two rows is continuous, the number of 10 or less villagers.

Output Format


Solution:
First, we can see that the range of data is so small hard pressure DP to form only a dozen key point we think puncturing point using \ (Floyd \) shortest distance
defined \ (f [x] [y ] [ p] \) represents a set of back-end x to y the current set point in the shortest possible time critical number of p
then we have two cases

  1. Cunmin find a point in the p-number
    F [X] [Y] [p] = min (F [X ^ (p <<. 1] [Y] [S] + W [S] [p]);
    2. At the end of several villagers down
    f [x] [y] [ en] = min (f [x ^ (1 << s] [y | (1 << s]] [k] + w [k] [en]);

Guess you like

Origin www.cnblogs.com/OIEREDSION/p/11620477.html