Problem description:
In a checkerboard consisting of 2 k × 2 k squares, a square is different from other squares. It is called a special square and a special checkerboard.
In the Board coverage problem, we need to use four different types of L-shaped bone cards in the figure to cover all squares except the special square on the given special board,
And no two L-type dominoes can overlap.
Analysis:
When k> 0, the 2 k × 2 k board is divided into 4 2k-1 × 2 k-1 sub-board (.
The special check box must be located in one of the four smaller check boards. The other three check boxes do not have special check boxes. To convert the three sub-boards without special squares into special ones,
You can use an L-type bone card to cover the union of the three smaller boards, as shown in (B), to convert the original problem into four smaller Board coverage problems.
Recursively use this split until the checker is simplified to a checker 1 × 1.
Instance:
Save the chessboard in a two-dimensional array. The bone number starts from 1, and the special square is 0. If it is a 4*4 chessboard, the special square is (), then the output of the program is
2 2 3 3
2 1 1 3
4 1 0 5
4 4 5 5
The same number is the same card.
[Cpp]
/*
Tr: the row number in the upper left corner of the checker;
Tc: the column number in the upper left corner of the Board;
Dr: the row number of the special square;
Dc: column number of the special square;
Size: size = 2 ^ k, the board size is 2 ^ k * 2 ^ k;
*/
Void chessBoard (int tr, int tc, int dr, int dc, int size)
{
If (1 = size) return;
Int t = tile ++, // L type bone number
S = size> 1; // split the Board
// Overwrite the sub-board in the upper left corner
If (dr <tr + s & dc <tc + s)
// Special square in this board
ChessBoard (tr, tc, dr, dc, s );
Else
{
// Use the t-shaped string to cover the lower right corner
Board [tr + s-1] [tc + s-1] = t;
// Overwrite the remaining squares
ChessBoard (tr, tc, tr + s-1, tc + s-1, s );
}
// Overwrite the sub-board in the upper right corner
If (dr <tr + s & dc> = tc + s)
// Special square in this board
ChessBoard (tr, tc + s, dr, dc, s );
Else // This Game Board has no special square
{
// Overwrite the lower left corner with the t-shaped L-shaped bone card
Board [tr + s-1] [tc + s] = t;
// Overwrite the remaining squares
ChessBoard (tr, tc + s, tr + s-1, tc + s, s );
}
// Overwrite the sub-board in the lower left corner
If (dr> = tr + s & dc <tc + s)
// Special square in this board
ChessBoard (tr + s, tc, dr, dc, s );
Else // overwrite the upper-right corner with the t-shaped L-bone card
{
Board [tr + s] [tc + s-1] = t;
// Overwrite the remaining squares
ChessBoard (tr + s, tc, tr + s, tc + s-1, s );
}
// Overwrite the sub-board in the lower right corner
If (dr> = tr + s & dc> = tc + s)
// Special square in this board
ChessBoard (tr + s, tc + s, dr, dc, s );
Else // overwrite the upper left corner with the t-shaped L-bone card
{
Board [tr + s] [tc + s] = t;
// Overwrite the remaining squares
ChessBoard (tr + s, tc + s, tr + s, tc + s, s );
}
}
/*
Tr: the row number in the upper left corner of the checker;
Tc: the column number in the upper left corner of the Board;
Dr: the row number of the special square;
Dc: column number of the special square;
Size: size = 2 ^ k, the board size is 2 ^ k * 2 ^ k;
*/
Void chessBoard (int tr, int tc, int dr, int dc, int size)
{
If (1 = size) return;
Int t = tile ++, // L type bone number
S = size> 1; // split the Board
// Overwrite the sub-board in the upper left corner
If (dr <tr + s & dc <tc + s)
// Special square in this board
ChessBoard (tr, tc, dr, dc, s );
Else
{
// Use the t-shaped string to cover the lower right corner
Board [tr + s-1] [tc + s-1] = t;
// Overwrite the remaining squares
ChessBoard (tr, tc, tr + s-1, tc + s-1, s );
}
// Overwrite the sub-board in the upper right corner
If (dr <tr + s & dc> = tc + s)
// Special square in this board
ChessBoard (tr, tc + s, dr, dc, s );
Else // This Game Board has no special square
{
// Overwrite the lower left corner with the t-shaped L-shaped bone card
Board [tr + s-1] [tc + s] = t;
// Overwrite the remaining squares
ChessBoard (tr, tc + s, tr + s-1, tc + s, s );
}
// Overwrite the sub-board in the lower left corner
If (dr> = tr + s & dc <tc + s)
// Special square in this board
ChessBoard (tr + s, tc, dr, dc, s );
Else // overwrite the upper-right corner with the t-shaped L-bone card
{
Board [tr + s] [tc + s-1] = t;
// Overwrite the remaining squares
ChessBoard (tr + s, tc, tr + s, tc + s-1, s );
}
// Overwrite the sub-board in the lower right corner
If (dr> = tr + s & dc> = tc + s)
// Special square in this board
ChessBoard (tr + s, tc + s, dr, dc, s );
Else // overwrite the upper left corner with the t-shaped L-bone card
{
Board [tr + s] [tc + s] = t;
// Overwrite the remaining squares
ChessBoard (tr + s, tc + s, tr + s, tc + s, s );
}
}