当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3593:Sea Base Exploration

题目描述

When the scientists explore the sea base, they use a kind of auto mobile robot, which has the mission to collect the swatches of resource of the sea base. The collections of the resource are taken to the research ship and classified, and then the research ship goes back to the mainland -- the research centre where scientists can do further research.

The robots have equipments to collect and store the resource, but the equipments have limited capability. Only a small quantity of each kind of recourse is enough for scientific research. So, once the robot has collected one kind of resource, it needs not to collect more. The capability of the robot is fixed and the same as the number of kinds of resource the scientists have already known. So, the robot will collect a list of resource and come back with fruitful results. The resource is buried beneath the surface of the sea base, and the quantity is always enough for the robot to collect if the map indicates that there are some. If the robot doesn't want to collect the resource underneath its location, it can leave it ignored and pass the square freely.

The robot needs a unit electric power to move from a square to another when its container is vacant and only can it move to a square adjacent to it. It needs Ai units to dig and collect the resource marked i. Each of the resource has its weight, so the robot costs Bi units of power per move after it has collected resource i.

During the sea base walk, the robot carries a battery with a certain units(P) of electric power, and the power of it need to be economized, the scientists ask you to calculate the minimal quantity of power the robot will use to collect all kinds of resource and back to the ship.

输入解释

The first line of the input is an integer T which indicates the number of test cases.

Each of the cases tells the map of the sea base you will explore, The first line will be the M, N, K, P. M (1 ≤ M ≤ 20) is the width of the area, N (1 ≤ N ≤ 20) is the length of the area, and K (1 ≤ K ≤ 10) is the number of kinds of resource, P is the certain capacity of the battery.

Then follows M lines characters indicating the map, each line contains N characters.

There are four kinds of characters, '.', '*', '#' and capital letters.

The symbol '.' indicate that free space. The '*' indicates where the research ship located, notice that once the robot moves back to this area, it will be fetched back to the main ship automatically. You can assume there is only one '*' on one map.The '#' indicates that the space is blocked of some reason, the capital letters indicate K kinds of resource, and you can assume that there are always K kinds of capital letters (alphabetically from A).

The next K lines follows two integers each line, Ai and Bi.

输出解释

For each input set output a number of the minimal quantity of power on one single line. Print a warning 'Impossible' if the minimal quantity of power needed exceeds the capacity of the battery or it's impossible for the robot to accomplish the mission.  

输入样例
1
5 5 1 50
*....
##.##
A#.#A
.#.#.
.....
1 0
输出样例
21

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3593

最后修改于 2020-10-29T07:05:26+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536