suizihan1226 @ 2024-10-10 20:55:20
#include<bits/stdc++.h>
using namespace std;
int a[3000][3000],b[3000][3000];
int n,m;
int cnt;
int fa[20],fb[20],fc[20];
void dfs(int h)
{
if(h>n)
{
cnt++;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==1)
{
b[i][cnt]=j;
}
}
}
return ;
}
for(int j=1;j<=n;j++)
{
if(fa[j]==0&&fb[h+j]==0&&fc[h-j+n]==0)
{
a[h][j]=1;
fa[j]=fb[h+j]=fc[h-j+n]=1;
dfs(h+1);
a[h][j]=0;
fa[j]=fb[h+j]=fc[h-j+n]=0;
}
}
}
int main(){
cin>>n;
dfs(1);
for(int i=1;i<=cnt;i++)
{
for(int j=1;j<=n;j++)
{
cout<<b[j][i]<<" ";
}
cout<<endl;
}
cout<<cnt;
return 0;
}
by Super_Cube @ 2024-10-10 20:58:21
@suizihan1226 你样例都没过啊。。。
by suizihan1226 @ 2024-10-10 21:01:58
@Super_Cube
#include<bits/stdc++.h>
using namespace std;
int a[1000][1000],b[1000][1000];
int n,m;
int cnt;
int fa[20],fb[20],fc[20];
void dfs(int h)
{
if(h>n)
{
cnt++;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==1)
{
b[i][cnt]=j;
}
}
}
return ;
}
for(int j=1;j<=n;j++)
{
if(fa[j]==0&&fb[h+j]==0&&fc[h-j+n]==0)
{
a[h][j]=1;
fa[j]=fb[h+j]=fc[h-j+n]=1;
dfs(h+1);
a[h][j]=0;
fa[j]=fb[h+j]=fc[h-j+n]=0;
}
}
}
int main(){
cin>>n;
dfs(1);
for(int i=1;i<=3;i++)
{
for(int j=1;j<=n;j++)
{
cout<<b[j][i]<<" ";
}
cout<<endl;
}
cout<<cnt;
return 0;
}
by suizihan1226 @ 2024-10-10 21:02:19
发错了!!!
by suizihan1226 @ 2024-10-10 21:03:07
@Super_Cube 人呢?
by suizihan1226 @ 2024-10-10 21:03:51
@Super_Cube 我都关注了!!!
by Super_Cube @ 2024-10-10 21:07:04
@suizihan1226 hack.
in:
11
ans:
1 3 5 7 9 11 2 4 6 8 10
1 3 6 9 2 8 11 4 7 5 10
1 3 7 9 4 2 10 6 11 5 8
2680