8-queen problem using Dynamic programming

后端 未结 2 531
情话喂你
情话喂你 2021-02-02 18:15

I am quite confused with idea of implementing 8-queen problem using dynamic programming. It seems it is not possible at one end as for DP \" if the problem was broken up into a

相关标签:
2条回答
  • 2021-02-02 18:34

    Just posting the obvious google hit:

    A dynamic programming solution to the n-queens problem

    Note: this is still very slow for large n's, O ( f(n)*8^n), you better use some other algorithm:

    A Polynomial Time Algorithm for the N-Queens Problem

    0 讨论(0)
  • 2021-02-02 18:55

    optimal solution for 7x7 board might not optimal as well (even incorrect) for 8x8.

    Yes, you are correct. But this is not a good way to split the problem. Look into paper yi_H posted in his answer, theorem 2.4, and look at the algorithm description. They divide the solutions into equivalence classes according to the sets of closed lines (i.e. lines which are threatened by queens). The theorem 2.4 guarantees that once they solve the sub-problem on the particular set of closed lines, they can solve the rest separately and then combine the result! Very clever.

    0 讨论(0)
提交回复
热议问题