计算机管道的实现的算法编程,利用C编程语言的方式怎么做的

Problem Description
The construction of office buildings has become a very standardized task. Pre-fabricated modules are combined according to the customer’s needs, shipped from a faraway factory, and assembled on the construction site. However, there are still some tasks that require careful planning, one example being the routing of pipes for the heating system.

Amodern office building ismade up of squaremodules, one on each floor being a service module from which (among other things) hot water is pumped out to the other modules through the heating pipes. Each module (including the service module) will have heating pipes connecting it to exactly two of its two to four neighboring modules. Thus, the pipes have to run in a circuit, from the service module, visiting each module exactly once, before finally returning to the service module. Due to different properties of the modules, having pipes connecting a pair of adjacent modules comes at different costs. For example, some modules are separated by thick walls, increasing the cost of laying pipes. Your task is to, given a description of a floor of an office building, decide the cheapest way to route the heating pipes.

Input
The first line of input contains a single integer, stating the number of floors to handle. Then follow n floor descriptions, each beginning on a new line with two integers, 2 <= r <= 10 and 2 <= c <= 10, defining the size of the floor – r-by-c modules. Beginning on the next line follows a floor description in ASCII format, in total 2r + 1 rows, each with 2c + 2 characters, including the final newline. All floors are perfectly rectangular, and will always have an even number of modules. All interior walls are represented by numeric characters, ’0’ to ’9’, indicating the cost of routing pipes through the wall (see sample input).

Output
For each test case, output a single line with the cost of the cheapest route.

Sample Input
3
4 3
#######

2 3

#1#9#1#

2 3

#1#7#1#

5 3

#1#9#1#

2 3

#######
4 4
#########

2 3 3

#1#9#1#4#

2 3 6

#1#7#1#5#

5 3 1

#1#9#1#7#

2 3 0

#########
2 2
#####

1

#2#3#

4

#####

Sample Output
28
45
10

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

4
C++语言编程 运用贪心算法的方法
1
数据结构上的一个线性表的冲突的解决,是不是用哈希算法怎么采用C语言的实现方式
0
用计算机软件编程实现的速记式加密算法的问题,如何用C语言的程序实现?
0
一个利用字符串规则实现的快速求和怎么使用C语言的方式编程实现算法计算
0
向下自动搜索算法的实现的思路,并且利用C语言编程的实现的方式
1
矩阵里元素交换的一个算法,如何利用C语言的编程的技术实现的办法
0
三元组队列的查询的算法,采用C语言编程的技术的实现的方式
0
数据结构的括号的嵌套的判断和匹配的算法,利用C语言编程实现
0
徒步旅行的算法问题的解释,采用C语言编程方式的实现
0
图案的拼接分配的一个算法问题的解决,如何利用C语言编程实现这个算法
0
C语言NxM二维数组实现Map的一个算法,用C语言编程的方式解决
0
曲线线段距离求和算法的一个判断,采用C语言编程语言的实现的方式
0
整数在数轴上排序后的比较算法问题,如何利用C语言的方式编程来实现
0
输入字符数组,然后进行关键字的查找的算法,利用C语言编程的实现
0
筷子的排序问题,采用组合算法的实现,如何利用C语言编程
0
NxN矩阵棋盘着色问题的符号处理,采用C语言算法编程的实现方式
0
组合问题的难度的控制算法,采用C语言编程的实现的方式
1
子集序列的最大连续值问题的算法,如何利用C语言的方式编程来实现
0
使用软件程序实现一个CRC的算法,怎么利用C语言编程的方式的实现
0
楼梯的台阶的高度的问题的算法的解决,怎么利用C语言的编程的思维的方式的技术