试题 算法提高 汉诺塔

 

代码:

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int step=0;    
int n,m;
void hanoi(int n,char A,char B,char C){
    if(n>=1){
        hanoi(n-1,A,C,B);
        step++;
        if(m==step){
            printf("#%d: %c->%c
",n,A,C);
        }
        hanoi(n-1,B,A,C);
    }
    
}
int main(){
    cin>>n>>m;
    hanoi(n,'A','B','C');
    cout<<(1<<n)-1<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/lusiqi/p/13767369.html