编程介的小学生 2017-12-06 02:28 采纳率: 20.5%
浏览 816
已采纳

Another Brick in the Wall

Problem Description
After years as a brick-layer, you've been called upon to analyze the structural integrity of various brick walls built by the Tetrad Corporation. Instead
of using regular-sized bricks, the Tetrad Corporation seems overly fond of bricks made out of strange shapes. The structural integrity of a wall can be
approximated by the fewest number of bricks that could be removed to create a gap from the top to the bottom. Can you determine that number for
various odd walls created by Tetrad?

Input
Input to this problem will begin with a line containing a single integer X (1 ≤ X ≤ 100) indicating the number of data sets. Each data set consists of
two components:

A single line, "M N" (1 ≤ M,N ≤ 20) where M and N indicate the height and width (in units), respectively, of a brick wall;
A series of M lines, each N alphabetic characters in length. Each character will indicate to which brick that unit of the wall belongs to. Note
that bricks will be contiguous; each unit of a brick will be adjacent (diagonals do not count as adjacent) to another unit of that brick. Multiple
bricks may use the same characters for their representation, but any bricks that use identical characters will not be adjacent to each other. All
letters will be uppercase.

Output
For each data set, output the fewest number of bricks to remove to create a gap that leads from some point at the top of the wall, to some point at the
bottom of the wall. Assume that bricks are in fixed locations and do not "fall" if bricks are removed from beneath them. A gap consists of contiguous
units of removed bricks; each unit of a gap must be adjacent (diagonals do not count) to another unit of the gap.

Sample Input
3
5 7
AABBCCD
EFFGGHH
IIJJKKL
MNNOOPP
QQRRSST
5 7
AABBCCD
AFFBGGD
IIJBKKD
MNNOOPD
QQRRSST
6 7
ABCDEAB
ABCFEAB
AEAABAB
ACDAEEB
FFGAHIJ
KLMANOP

Sample Output
5
2
2

  • 写回答

1条回答 默认 最新

  • devmiao 2017-12-11 16:09
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择