编程介的小学生 2017-03-26 08:08 采纳率: 20.5%
浏览 745
已采纳

Water Pipe

Two waterworks want to connect to each other with water pipes. Just as the map shows, the waterworks sit on two corners of the city. The city is a rectangle, and is divided into a lot of small squares. Water pipes are placed in these squares. Only one pipe can be placed in each square. There are two types of pipe: straight pipe and bend pipe. You can rotate them if necessary. Two types of pipe have different prices. You are assigned to calculate the minimum cost to connect the two waterworks.

Input:

There are several test cases. Each test case contains two parts.

The first part is a line of for integers: the width of the city, the length of the city, the price of the straight pipe, the price of the bend pipe(1<=width,length<=100, 0<=price<=100).

The second part is a map of the city, "b" stands for block on that square, while "*" stands for a blank square which you can place water pipe in.

Output:

For each test case, print in one line the minimum cost to connect the waterworks. If can not to connect to each other, output "impossible".

Sample Input:

1 2 3 4
*
*
5 5 8 0
b****


**bb*
**bb*


5 5 8 10
b****


**bb*
**bb*


1 1 38 89
*
1 1 3 3
b
Sample Output:

8
8
76
38
impossible

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-04-04 15:22
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计