1.汉诺塔问题
#include <stdio.h>void move(char x, char y)
{printf("%c -> %c\n", x, y);
}void Hanoi(int n, char a, char b, char c)
{if (n == 1){move(a, c);}else{Hanoi(n - 1, a, c, b);move(a, c);Hanoi(n - 1, b, a, c);}
}int main()
{int n = 0;scanf("%d", &n);Hanoi(n, 'a', 'b', 'c');return 0;
}
2.青蛙跳台阶问题
#include <stdio.h>int dance_step(int n)
{if (n == 1)return 1;if (n == 2)return 2;if (n == 3)return 4;if (n > 3)return dance_step(n - 1) + dance_step(n - 2) + dance_step(n - 3);
}int main()
{int n = 0;scanf("%d", &n);int sum = dance_step(n);printf("%d\n", sum);return 0;
}