题目链接: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
****************************************************************/

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-26
  • 2021-12-25
  • 2021-08-30
  • 2022-12-23
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案