Instantly share code, notes, and snippets.

# jwon0615/1916.cpp Created Mar 26, 2018

3_codeup_연습문제_재귀
 #include int fibo(int n, int a, int b){ if (n==0) { return a; } fibo(n-1, b,(a+b)%10009); } int main(){ int n; scanf("%d", &n); printf("%d", fibo(n, 0, 1)); return 0; }
 #include int sum; int f(int n){ if(n>0) { sum = sum*10 + n%10; return f(n/10); } else return sum; } int main(){ int a; scanf("%d",&a); printf("%d",f(a)); }
 #include void f(int k){ if(k/2) f(k/2); printf("%d", k%2); } int main(){ int n; scanf("%d", &n); f(n); }
 #include void f(int k){ if (k==1) ; else{ if (k%2) f(3*k+1); else f(k/2); } printf("%d\n", k); } int main(){ int n; scanf("%d", &n); f(n); }
 #include void hanoi(int k, char from, char by, char to){ if(!k) return; hanoi(k-1,from,to,by); printf("Disk %d : %c to %c\n", k, from, to); hanoi(k-1,by,from,to); } int main(){ int n; scanf("%d", &n); hanoi(n,'A','B','C'); }
 #include int cnt=0; void hanoi(int k, char from, char by, char to){ if(!k) return; hanoi(k-1,from,to,by); cnt++; hanoi(k-1,by,from,to); } int main(){ int n; scanf("%d", &n); hanoi(n,'A','B','C'); printf("%d", cnt); } /* #include int main(void) { int n; scanf("%d",&n); printf("%d",(1< int hanoi(int n){ if(n==1) return 1; else return 2*hanoi(n-1)+1; } int main(){ int n; scanf("%d", &n); printf("%d", hanoi(n)); return 0; } */
 #include int memo[100005] = {1, 1, 2}; int f(int k){ if (memo[k]) return memo[k]; else return memo[k] = (f(k-3) + f(k-2) + f(k-1)) % 1000; } int main(){ int x; scanf("%d", &x); printf("%d", f(x)); } /* #include int main(){ int n,i; int a[100005]; scanf("%d",&n); a[0]=1; a[1]=1; a[2]=2; for(i=3;i<=n;i++) a[i]=(a[i-1]+a[i-2]+a[i-3])%1000; printf("%d",a[n]); } */