显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstring>
#define maxn 20
using namespace std;
int n;
int s[maxn]={0};
int cnt=0,ans=0;
void dfs(int i,int x1,int x2,int l){
if (i>n){
ans++;
if (cnt<3){
cnt++;
for (int j=1;j<=n;j++){
printf("%d ",s[j]);
}
printf("\n");
}
return;
}
int k=1;
for (int j=1;j<=n;j++){
k<<=1;
if ( (k&x1)|(k&x2)|(k&l) ) ;
else{
s[i]=j;
dfs(i+1,(k|x1)>>1,(k|x2)<<1,k|l);
}
}
return;
}
int main(){
freopen("checker.in","r",stdin);
freopen("checker.out","w",stdout);
scanf("%d",&n);
dfs(1,0,0,0);
printf("%d\n",ans);
}