标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 16803 Accepted Submission(s): 7631
#include<stdio.h> #include<math.h> int x[15],y[15]={0}; int sum,n; int place(int k) { int i; for(i=1;i<k;i++) { if(abs(k-i)==abs(x[k]-x[i])||x[k]==x[i]) return 0; } return 1; } void DFS(int a) { int i; if(a>n) sum++; else for(i=1;i<=n;i++) { x[a]=i; if(place(a)) DFS(a+1); } } int main() { int i,j,n1; for(i=1;i<=10;i++) { n=i; sum=0; DFS(1); y[i]=sum; } while(scanf("%d",&n1)==1&&n1) { printf("%d\n",y[n1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wangmenghan/p/5472445.html