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

建议使用的浏览器:

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

3295:An interesting mobile game

题目描述
XQ,one of the three Sailormoon girls,is usually playing mobile games on the class.Her favorite mobile game is called “The Princess In The Wall”.Now she give you a problem about this game.
Can you solve it?The following picture show this problem better.

This game is played on a rectangular area.This area is divided into some equal square grid..There are N rows and M columns.For each grid,there may be a colored square block or nothing.
Each grid has a number.
“0” represents this grid have nothing.
“1” represents this grid have a red square block.
“2” represents this grid have a blue square block.
“3” represents this grid have a green square block.
“4” represents this grid have a yellow square block.

1. Each step,when you choose a grid have a colored square block, A group of this block and some connected blocks that are the same color would be removed from the board. no matter how many square blocks are in this group.
2. When a group of blocks is removed, the blocks above those removed ones fall down into the empty space. When an entire column of blocks is removed, all the columns to the right of that column shift to the left to fill the empty columns.

Now give you the number of the row and column and the data of each grid.You should calculate how many steps can make the entire rectangular area have no colored square blocks at least.
输入解释
There are multiple test cases. Each case starts with two positive integer N, M,(N, M <= 6)the size of rectangular area. Then n lines follow, each contains m positive integers X.(0<= X <= 4)It means this grid have a colored square block or nothing.
输出解释
Please output the minimum steps.
输入样例
5 6
0 0 0 3 4 4
0 1 1 3 3 3
2 2 1 2 3 3
1 1 1 1 3 3
2 2 1 4 4 4
输出样例
4

提示

0 0 0 3 4 4     0 0 0 4 4 0    0 0 0 0 0 0    0 0 0 0 0 0    0 0 0 0 0 0
0 1 1 3 3 3     0 0 3 3 3 0    0 0 0 0 0 0    0 0 0 0 0 0    0 0 0 0 0 0
2 2 1 2 3 3     0 0 3 3 3 0    0 0 0 0 0 0    0 0 0 0 0 0    0 0 0 0 0 0
1 1 1 1 3 3     2 2 2 3 3 0    2 2 2 4 4 0    2 2 0 0 0 0    0 0 0 0 0 0
2 2 1 4 4 4     2 2 4 4 4 0    2 2 4 4 4 0    2 2 2 0 0 0    0 0 0 0 0 0
来自杭电HDUOJ的附加信息
Author B.A.C
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3295

最后修改于 2020-10-25T23:02:04+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000/1000MS(Java/Others) 65535/32768K(Java/Others)