ans

x-wangziji 2022-05-04 11:37:21 17 返回题目

#include<bits/stdc++.h>
using namespace std;
int n,tot;
int lie[50],djx1[50],djx2[50];

void dfs(int x){
	if(x>n){
		tot++;
		return;
	}
	for(int y=1;y<=n;y++){
		if(lie[y]==1) continue;
		if(djx1[x+y]==1) continue;
		if(djx2[x-y+n]==1) continue;
		lie[y]=1;
		djx1[x+y]=1;
		djx2[x-y+n]=1;
		dfs(x+1);
		lie[y]=0;
		djx1[x+y]=0;
		djx2[x-y+n]=0;
	}
}


int main(){
	cin>>n;
	dfs(1);
	cout<<tot;
	return 0;
}
{{ vote && vote.total.up }}