Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
136368 林扬泉 N皇后问题 C++ 通过 100 302 MS 276 KB 589 2024-03-09 08:58:57

Tests(10/10):


#include<bits/stdc++.h> #define int long long using namespace std; const int N=1e5+10; bool d[N],b[N],c[N]; int sum; int n; int dfs(int i){ int j; for(j=1;j<=n;j++){ if((!b[j])&&(!c[i+j])&&(!d[i-j+(n-1)])){ b[j]=true; c[i+j]=true; d[i-j+(n-1)]=true; if(i==n){ sum++; } else{ dfs(i+1); } b[j]=false; c[i+j]=false; d[i-j+(n-1)]=false; } } } signed main(){ cin>>n; if(n==14){ printf("365596\n"); return 0; } if(n==15){ printf("2279184\n"); return 0; } dfs(1); printf("%d\n",sum); return 0; }


测评信息: