1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| struct Edge { int to,next,ve; Edge(){} Edge(int v,int w,int x):to(v),next(w),ve(x){} } edge[maxn]; int head[maxn],cnt;
void addedge(int u,int v) { if (u==v) return; edge[cnt]=Edge(v,head[u],v); head[u]=cnt++;
}
bool vis[maxn]; int n,N; vector<int> vec;
void init() { memset(head,-1,sizeof(head)); cnt=0;
for(int i=0;i<N;i++) {
addedge(i+1,(i<<1)%N+1); addedge(i+1,((i<<1)|1)%N+1); } }
void dfs(int u) {
for(int i=head[u];i>-1;i=edge[i].next) { int v=edge[i].to; if (vis[edge[i].ve]) continue; vis[edge[i].ve]=1; vec.push_back(edge[i].ve); dfs(v); } }
int main() { while(~scanf("%d",&n)) { N=1<<n; init(); vec.clear();
CLEAR(vis,maxn); dfs(1); cout<<N<<' '; for(int i=0;i<vec.size();i++) cout<<(vec[i]&1); cout<<endl; } return 0; }
|