EOJ 1821 Hanoi Tower III

http://acm.cs.ecnu.edu.cn/problem.php?problemid=1821

这题就等价于普通的汉诺塔,只是每一层移动两次,原来需要2^n - 1次,则现在需要2^(n + 1) - 2次,递推式为f(i) = 2 * f(i - 1) + 2

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 unsigned long long f[62];
 5 int main()
 6 {
 7     f[1] = 2;
 8     for (int i = 2; i < 62; i++)
 9         f[i] = f[i - 1] * 2 + 2;
10     int n;
11     while (cin >> n)
12         cout << f[n] << endl;
13     return 0;
14 }
View Code

 

posted on 2013-06-21 13:12  KimKyeYu  阅读(182)  评论(0编辑  收藏  举报

导航