在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。Sample Input1 8 5 0Sample Output1 92 101 #include 2 main()3 {4 int n,a[13]={0,1,0,0,2,10,4,40,92,352,724,2680,14200};5 ... Read More
posted @ 2013-06-21 18:06 瓶哥 Views(246) Comments(0) Diggs(0) Edit
用数组模拟的位运算,虽然模拟的很拙劣。。但是至少比普通搜索快1倍。 1 #include <cstdio> 2 #include <cstring> 3 #include <ctime> 4 #include <cstdlib> 5 const int SIZE = 12; 6 int sum=0,row[SIZE]={0},ld[SIZE]={0},rd[SIZE]={0}; 7 void L_m(int *a) 8 { 9 for(int i=0;i<SIZE-1;i++)10 a[i]=a[i+1];11 a[SIZE-1]=0;12 Read More
posted @ 2013-06-21 11:20 瓶哥 Views(161) Comments(0) Diggs(0) Edit