```cpp
#include <bits/stdc++.h>
using namespace std;
int n,vis[20],b[30],c[30],ans[20],cnt;
bool legal(int h,int l) {
if((!vis[l])&&(!b[h+l])&&(!c[h-l+n]))
return true;
else
return false;
}
void dfs(int h) {
if(h==n+1) {
cnt++;
if(cnt<=3) {
for(int i=1; i<=n; ++i)
printf("%d ",ans[i]);
printf("\n");
}
}
for(int i=1; i<=n; ++i) {
if(legal(h,i)) {
ans[h]=i;
vis[i]=1,b[h+i]=1,c[h-i+n]=1;
dfs(h+1);
vis[i]=0,b[h+i]=0,c[h-i+n]=0;
}
}
}
int main() {
ios::sync_with_stdio(false);
scanf("%d",&n);
dfs(1);
printf("%d",cnt);
return 0;
}
```
您可以吸氧气,或者像我一样用$\text{ios::sync with stdio(false);}$
by Eason_AC @ 2019-03-30 16:53:20
@[Eason_AC](/space/show?uid=112917)
吸氧气貌似没有用
by 201810tflsdjl @ 2019-04-06 18:43:21
@[201810tflsdjl](/space/show?uid=161876) 那您就参考一下我的代码吧
by Eason_AC @ 2019-04-06 22:53:05
@[201810tflsdjl](/space/show?uid=161876) 那您就参考一下我的代码吧
by Eason_AC @ 2019-04-06 22:53:09