The project of building a swimming pool has been suggested to you and you want to build…
- User
The project of building a swimming pool has been suggested to you and you want to build this pool. "Pool enclosure" is a rectangular grid consisting of w x h w×h is a square plot of land consisting of zero or a number of pools (which may not be connected). A "pool" consists of one or more interconnected pits, which will later be filled with water.
At first you are given a piece of land, each part of which is either a pit (.) or a flat grass field (#). In order to convert this land into a swimming pool, you must do the following:
You can leave an episode as it is at no cost to you. Excavate a flat lawn and create a pit that costs d d is large. Fill a hole and create a flat lawn that costs f f is large. A wall should be created at the border of each pit and flat lawn so that the pool water is not wasted. The cost of building a wall between two adjacent pieces of land b b is large. The plot of border land "pool area" must be grass land. You have to build this "pool area" as cheaply as possible with the given plan from the available plot of land.
input The first line contains a positive integer that specifies the number of input samples (up to 100) then for each input:
A line contains two integers w , h w, h ( 2 ≤ w , h ≤ 50 2≤w, h≤50): Width and length of the land to be built. Three lines containing three integers d d, f f and b b ( 1 ≤ d , f , b ≤ 10,000 1≤d,f,b≤10000): respectively, the cost of creating a new pit, the cost of filling an existing pit, and the cost of building a wall between a piece of pit and a piece of grass. In the following h h line each included w w character that specifies the initial plot. output For each sample input, one line contains an integer specifying the cost of building the cheapest possible "pool zone" from the initial plot of land.
Example Sample input: 3 3 3 5 5 1 #.# #.#
5 4 181 #..## ##.## #.#.#
2 2 27 11 11 #. .# Plain text Sample output: 9 27 22
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.