syf159 @ 2024-05-05 21:12:48
#include<bits/stdc++.h>
using namespace std;
long long n,ans,a[15],cnt;
bool l[15],djx1[15],djx2[15];
void cout_()
{
for(int i=1; i<=n; i++)
{
cout<<a[i]<<" ";
}
cout<<"\n";
}
void dog(int i)
{
if(i>n)
{
if(ans<3)
{
cout_();
}
ans++;
return ;
}
for(int j=1; j<=n; j++)
{
if(l[j]==0&&djx1[i+j]==0&&djx2[i-j+n]==0)
{
l[j]=1;
djx1[i+j]=1;
djx2[i-j+n]=1;
a[i]=j;
dog(i+1);
l[j]=0;
djx1[i+j]=0;
djx2[i-j+n]=0;
}
}
}
int main(){
cin>>n;
dog(1);
cout<<ans<<endl;
return 0;
}
下载了样例,测过,没问题,提交上去3AC,其他WA
by L_zaa_L @ 2024-05-05 21:30:30
@syf159 数组开大一些。
by syf159 @ 2024-05-07 17:11:27
@zaa thanks,一罐
by syf159 @ 2024-05-07 17:16:19
A了