yueluoxingchen @ 2024-07-09 12:02:19
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int N=15;
int res[N],a[N],b[N],c[N];
int n,cnt;
void print()
{
cnt++;
//cout<<cnt<<endl;
if(cnt<=3) for(int i=1;i<=n;i++) cout<<res[i]<<" ";
if(cnt<=3) cout<<endl;
}
void dfs(int ha)
{
if(ha>n)
{
print();
return;
}
for(int i=1;i<=n;i++)
{
if(!a[i] && !b[ha+i] && !c[ha-i+n])
{
a[i]=b[ha+i]=c[ha-i+n]=1;
res[ha]=i;
dfs(ha+1);
a[i]=b[ha+i]=c[ha-i+n]=0;
}
}
}
int main()
{
cin>>n;
dfs(1);
cout<<cnt<<endl;
return 0;
}
by yueluoxingchen @ 2024-07-09 12:05:29
36分,打错了
by yueluoxingchen @ 2024-07-09 12:05:48
问题好像出在cnt上
by fuchenxi666 @ 2024-07-09 12:43:47
把N改成105就行了,cnt没有问题
by yueluoxingchen @ 2024-07-09 13:08:55
@fuchenxi666 谢谢,感觉自己像个智减员
by yueluoxingchen @ 2024-07-09 13:49:48
@fuchenxi666 已关
by fuchenxi666 @ 2024-07-09 14:03:38
你是哪个城市的