ZZY的八皇后

来源:互联网 发布:it程序员学徒干什么的 编辑:程序博客网 时间:2024/05/16 00:37
#include<iostream> 
#include<iostream>
using namespace std;
int a[80],b[80],ans,c[80],i,n,j; 
void f(int i,int n){
if(i>n){
ans++;
return;
}
for(int j=1;j<=n;j++){
if(!a[j]&&!b[i+j]&&!c[i-j+8]){
a[j]=true;b[i+j]=true;c[i-j+8]=true;
f(i+1,n);
a[j]=false;b[i+j]=false;c[i-j+8]=false;
}
}

int main(){
cin>>n;
f(1,n);
cout<<ans;
}
0 0