HDU 5180 state compression DP hit table
Test instructions
In N*n's chess, a number of kings and K-cars were placed, so that the king did not attack each other, the car did not attack each other, the car can not attack the King (this does not mean that the king can not attack the car). The king can attack to it up and down, left upper left lower right upper right bottom eight positions of chess pieces, the car can attack to the same row or the same column of pieces, the total number of solutions to 1000000007 modulo value.
Limitations:
1 <= N <=15; 0 <= k <=15
ideas:
State compression, DP, playing table set
The table program is as follows:
Table Program 1:
TAB[A][B] Represents the number of a*b of a checkerboard king.
Because only 15*15, you can use state compression DP to solve.
Table Program 2:
Based on table 1 and then the table 2,
Table 2 is the answer table.
Because the problem is only 15*16, for each case: (N,K), first consider the situation of K car, you can use two binary number to represent the distribution of K car on the board, and then you can find the essence of the car is divided into several parts, the king of each part of the placement of the table 1 has been played, The rest of the section can be easily calculated.
PS: This program must be well optimized, or to play a long time, I probably want to run around 10min.
HDU 5180 state compression DP hit table