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