#include<iostream>
#include<string.h>
using namespace std;
int n;
int num=0;
int limit;
void test(int row,int ld,int rd){
if(row!=limit){
int pos=limit&~(row|ld|rd);
while(pos){
int p=pos&-pos;
pos=pos-p;
test(row+p,(ld|p)<<1,(rd|p)>>1);
}
}
else num++;
}
int main(){
cin >> n;
limit=(1<<n)-1;
test(0,0,0);
cout << num;
return 0;
}
点击打开链接
八皇后位运算优化
最新推荐文章于 2022-07-13 18:12:48 发布