Test instructions
For an 8x8 matrix, there are 6 colors to choose from, each time can only change the top left corner of the color, the result is that all points connected with the point is dyed that color, asked at least several times can be the whole picture to dye the same color.
Solution:
A * search, the valuation function is, if you choose the color K, you can have how many lattice in this operation is added to the connected block, if the value of 0, then cut off.
VIS[I][J] may be 0 1 2 for 1 means that the point is in the connected block, and 2 means that the point is adjacent to the connected block, otherwise 0.
For the current situation, we can find out how many more colors are available outside of the connected block, and the minimum number of operations may be required to accomplish this. It's just possible. We set the number of outer-block colors in the initial diagram to the minimum number of operands that could be done. Based on this operand, we are going to verify that it is feasible. If it is not feasible, the number +1, then to verify. Until a workable solution is found.
Pending repair.
HDU 4127 * Search