The mutilated chessboard (defective chessboard) is a chessboard with 2kx2k squares, in which there is just a lattice deformity. Fig. 2-3 gives a variety of possible mutilated chessboard when k≤2, where the mutilated squares are shaded. Note that when k= 0 o'clock, there is only one possible mutilated chessboard (shown in Figure 1, 4-3 a). In fact, for any k, there is just 22k of different mutilated chessboard.
The problem with the defective chessboard requires that the defective chessboard (shown in Figure 1 4-4) be covered with a triple panel (T r i o m i n o e s). In this overlay, the two panels cannot overlap, and the three panels cannot cover the mutilated squares, but all the other squares must be covered. Under this restriction, the total number of panels required is (22K-1)/3. You can verify that (22k-1)/3 is an integer. A mutilated chessboard of K 0 is easily covered because it has no incomplete squares, and the number of panels used for covering is 0. When k= 1 o'clock, there are just 3 non-mutilated squares, and these three squares can be covered with a three-grid plate in one Direction in Figure 1 4-4.
Divide-and-conquer method can solve the problem of the defective chessboard well. This method can transform the problem of covering the 2kx2k defective chessboard into a small incomplete chessboard. A natural way to 2kx2k a chessboard is to divide it into 4 2k-1x2k-1 chessboard as shown in Figure 1, 4-5 A. Note that when this division is completed, only one of the 4 small chessboard has a broken square (because the original 2kx2k chessboard has only one mutilated square). First, cover the 2k-1x2k-1 mutilated chessboard which contains the mutilated squares, then the remaining 3 small chessboard into a defective chessboard, for which a three-grid board in the 3 small chessboard formed by the angle, as shown in Figure 14-5b, where the original 2kx2k chessboard of the broken square into the upper left corner of the 2k-1x2k-1 Board. This segmentation technique can be used recursively to cover 2kx2k mutilated chessboard. When the size of the chessboard is reduced to 1x1, the recursive process terminates. At this point, the 1x1 board contains only one square and the square is incomplete, so there is no need to place a three-grid plate.
The above divide and conquer algorithm can be written into a recursive C + + function Ti l e B o a r d (see Program 1 4-2). The function defines a global two-dimensional integer array variable b o a r d to represent the chessboard. B o a R d [0] [0] represents the square in the upper-left corner of the chessboard. The function also defines a global integer variable t i l e with an initial value of 0. The input parameters for the function are as follows:
? The row in the upper-left corner of the TR chessboard.
? The column of the upper-left corner of the TC chessboard.
? The line where the Dr Incomplete box is located.
? The column that contains the DL incomplete box.
? The number of rows or columns of the size chessboard.
The calling format of Ti l e b o a r d function is ti l e b o a r d (0,0, Dr, Dc,size), where s i z e = 2k. The number of panels required to cover the mutilated chessboard is (s i z e2-1)/3. The function tileboard the three grids with integers 1 through (s I z e2-1)/3来, and marks the three-grid plates with the unmarked squares that are covered by the three-grid plate.
Make T (k) The time it takes for a function ti l e B o a r d to cover a 2kx2k mutilated chessboard. When k= 0 o'clock, s i z e equals 1, covering it will cost constant time D. When k > 0 o'clock, 4 recursive function calls are made, and these calls take a time of 4t (k-1). In addition to these times, it takes time for the if condition to test and overwrite 3 non-mutilated squares, assuming that the additional time is represented by constant C. You can get the following recursive expression: