HDU 5180 state compression DP hit table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.