#include <stdio.h>
int memo[100000000];
// 인접통행 하노이의 탑
void move(int n, char from, char to, char by)
{
printf("%d : %c -> %c\n", n, from,to);
}
int hanoi(int n, char from, char to, char by)
{
if (n == 1)
{
printf("1 : A -> B\n");
printf("1 : B -> C\n");
}
else
{
hanoi(n-1, from ,to, by);
hanoi(n-1,to,by,from);
move(n , from , to, by);
hanoi(n-1, by, to,from);
}
}
int count(int n)
{
if(n==1)
return 3;
return memo[n]=3*count(n-1);
}
int main()
{
char A,B,C;
int i;
scanf("%d", &i);
hanoi(i, A, C, B);
printf("%d", count(i)-1);
return 0;
}
코드 이렇게 짰는데 어디를 고쳐야 할 까요?
댓글 0