In a checkerboard consisting of 2 ^ k * 2 ^ k Square, there is a square occupied, and the four L-shaped bone cards are used to cover all the squares on all the checkerboards, which cannot overlap.
The Code is as follows:
def chess(tr,tc,pr,pc,size):global mark global tablemark+=1count=markif size==1:returnhalf=size//2if pr<tr+half and pc<tc+half:chess(tr,tc,pr,pc,half)else:table[tr+half-1][tc+half-1]=countchess(tr,tc,tr+half-1,tc+half-1,half)if pr<tr+half and pc>=tc+half:chess(tr,tc+half,pr,pc,half)else:table[tr+half-1][tc+half]=countchess(tr,tc+half,tr+half-1,tc+half,half)if pr>=tr+half and pc<tc+half:chess(tr+half,tc,pr,pc,half)else:table[tr+half][tc+half-1]=countchess(tr+half,tc,tr+half,tc+half-1,half)if pr>=tr+half and pc>=tc+half:chess(tr+half,tc+half,pr,pc,half)else:table[tr+half][tc+half]=countchess(tr+half,tc+half,tr+half,tc+half,half)def show(table):n=len(table)for i in range(n):for j in range(n):print(table[i][j],end='')print('')mark=0n=8table=[[-1 for x in range(n)] for y in range(n)]chess(0,0,2,2,n)show(table)
N is the checkerboard width and must be 2 ^ k. n = 8 in this example. The special lattice is at (2, 2), as shown in:
Divide and conquer the Board into four parts each time. If the special lattice is in this small board, it is further divided into four parts, if it is not in this small board, place the lattice located near the center of the Small board, indicating that 1/3 of the L-type dominoes occupies this position. Each recursion will traverse and query four small boards, the three grids with no special checkerboard positions constitute a complete L-shaped card in the center of the large checkerboard, and so on. The running result is as follows:
Reprinted Please note: