- 567 名前:デフォルトの名無しさん mailto:sage [2008/11/11(火) 07:36:20 ]
- >>564
なんかへたくそでごめん。。 #include<stdio.h> #define N 100 int n,cnt=0,c[N],b[N]; void solve(int a_top,int b_top,int c_top){ if(a_top>n && b_top==0){ int i; for(i=0;i<n;i++)printf("%d",c[i]); printf("\n"); cnt++; } if(a_top<=n){ b[b_top++] = a_top++;//a->b solve(a_top,b_top,c_top); b[--b_top] = --a_top;//b->a } if(b_top>0){ c[c_top++]=b[--b_top];//b->c solve(a_top,b_top,c_top); b[b_top++]=c[--c_top];//c->b } } int main(){ printf("n:"); scanf("%d",&n); if(n>0) solve(1,0,0); printf("%d\n",cnt); }
|

|