2014
02-17

# DeBruijin

3

8 00010111

XLK题解（有改动）：

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;
bool fg,d[1<<15],vis[1<<15];
int tot,k;
{
memset(vis,0,sizeof vis);
fg=false;
tot=1<<k;
}
bool check()
{
int i=1,j=tot+1;
for(;i<=k-1;i++,j++)
{
if(d[i]!=d[j]) return false;
}
fg=true;
for(i=1;i<=tot;i++) printf("%d",d[i]);
}
void dfs(int step,int num)
{
if(fg) return;
if(step==tot)
{
check();
return;
}
for(int i=0;i<tot;i++)
{
if(!vis[i])
{
int sk;
if((num>>(k-1))==1) sk=num-(1<<(k-1));
else sk=num;
if(sk==(i>>1))
{
d[step+k]=i&1;
vis[i]=true;
dfs(step+1,i);
vis[i]=false;
}
}
}
}
void go()
{
printf("%d ",tot);
for(int i=1;i<=k;i++) d[i]=0;
vis[0]=true;
dfs(1,0);
printf("\n");
}
int main()
{
while(scanf("%d",&k)!=EOF)
{
go();
}
return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int p,d[1<<15],n;
bool vis[1<<15];
void prev()
{
memset(vis,0,sizeof vis);
p=0;
}
void dfs(int u)
{
int to1=(u<<1)&((1<<n)-1);
int to2=to1+1;
if(!vis[to1])
{
vis[to1]=true;
dfs(to1);
d[++p]=0;
}
if(!vis[to2])
{
vis[to2]=true;
dfs(to2);
d[++p]=1;
}
}
void go()
{
dfs(0);
printf("%d ",1<<n);
for(int i=1;i<n;i++) printf("0");
for(int i=p;i>=n;i--) printf("%d",d[i]);
printf("\n");
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
prev();
go();
}
return 0;
}

, ,
1. simple, however efficient. A lot of instances it is difficult to get that a??perfect balancea?? among usability and appearance. I must say that youa??ve done a exceptional task with this. Also, the blog masses quite fast for me on Web explore.