Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
136506 熊婉月 N皇后问题 C++ 解答错误 20 2011 MS 272 KB 580 2024-03-09 10:01:42

Tests(2/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,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; }


测评信息: