显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int n,full,c,rec[20];
int lowbit(int num)
{
return(-num&num);
}
void dfs(int deep,int la,int lb,int lc)
{
if ((la&full)==full)
{
if (c<3)
{
for (int i=1;i<n;i++)
cout<<rec[i]<<' ';
cout<<rec[n]<<endl;
}
c++;
return;
}
int temp,pos,now=(la|lb|lc);
temp=(~now)&full;
while (temp)
{
pos=lowbit(temp);
temp-=pos;
if (c<3)
rec[deep]=log(pos*1.0)/log(2.0)+1;
dfs(deep+1,la|pos,(lb|pos)<<1,(lc|pos)>>1);
}
}
int main(void)
{
freopen("checker.in","r",stdin);
freopen("checker.out","w",stdout);
cin>>n;
full=(1<<n)-1;
dfs(1,0,0,0);
cout<<c<<endl;
return(0);
}