首页 > 代码库 > 题目1458:汉诺塔III(不一样的汉诺塔递归算法)

题目1458:汉诺塔III(不一样的汉诺塔递归算法)

题目链接:http://ac.jobdu.com/problem.php?pid=1458

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

////  1458 汉诺塔III.cpp//  Jobdu////  Created by PengFei_Zheng on 23/04/2017.//  Copyright © 2017 PengFei_Zheng. All rights reserved.// #include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <cmath> using namespace std;int ans = 0; long long hanoi(int n){    if(n==0) return 0;    if(n==1) return 2;    return 3*hanoi(n-1)+2;} int n; int main(){    while(scanf("%d",&n)!=EOF){        printf("%lld\n",hanoi(n));    }}/**************************************************************    Problem: 1458    User: zpfbuaa    Language: C++    Result: Accepted    Time:0 ms    Memory:1520 kb****************************************************************/

 

题目1458:汉诺塔III(不一样的汉诺塔递归算法)