HDU 2553 N Queen question

Source: Internet
Author: User

N Queen's question


Problem description placed n Queens on the N*n's checkered chessboard, making them not attack each other (that is, any 2 queens are not allowed to be in the same row, in the same column, or in a diagonal line with a 45-angle checkerboard border.)
Your task is to find out how many legal placement methods are available for a given n.

Input has several lines, one positive integer n≤10 per line, indicating the number of boards and queens, or, if n=0, the end.

Output has several rows, one positive integer per line, representing the number of different placements of the queen corresponding to the input row.

Sample INPUT1 85 0

Sample Output19210
1#include <cstdio>2 using namespacestd;3 4 intc[ One];5 intCNT;6 7 voidDfsintCurintN)8 {9     if(cur==N)Ten     { Onecnt++; A         return; -     }  -      for(intI=0; i<n;i++) the     { -         intok=1; -c[cur]=i; -          for(intj=0; j<cur;j++) +         { -             if(c[j]==c[cur]| | cur-c[cur]==j-c[j]| | cur+c[cur]==j+C[j]) +             { Aok=0; at                  Break; -             } -         } -         if(OK) -DFS (cur+1, n); -     } in } -  to intMain () + { -     intN; the     inta[ One]; *      for(intI=1; i<=Ten; i++) $     {Panax NotoginsengCnt=0; -Dfs0, i);  thea[i]=CNT; +     } A      while(SCANF ("%d", &n) &&N) the     { +printf"%d\n", A[n]); -     } $     return 0; $}

HDU 2553 N Queen question

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.