Total passenger garlic Tower of Hanoi

Tower of Hanoi (also known as the Tower of Hanoi) problem stems from an ancient Indian legend of educational toys. When Brahma created the world to do three diamond pillars, from the bottom up pile with 6464 gold disc in accordance with the order in a post. Brahma Brahman command to the disk in order of size from the bottom again placed on the other pillars. And predetermined, the disc can not be enlarged in a small disk, a disk can only be moved between the three pillars.


Jun garlic now start playing the game Tower of Hanoi, he put a piece of gold nn disc on the first pillar, from top to bottom are numbered 1-n1-n, the minimum number of 11 discs, disc largest number nn. Jun garlic mobile No. ii ii disc when it takes stamina points. Now garlic king wants to move all the disks in the end on the 22 pillars, the process of moving garlic quasi-monarch must observe rules of the game.


Now garlic Jun want to know the minimum number of moves to complete a game of his physical strength and minimal consumption.


Input format


enter a positive integer n (1 \ le n \ le 60) n (1≤n≤60) represents the number of golden disks


output format


line of output number 22, it represents the minimum number of movements and the smallest physical consumption, intermediate separated by a space.


Input 1 Sample


2
Sample Output 1


. 3. 4
Sample Input 2


. 3
Sample Output 2


7 11


#include <stdio.h>
#include <stdlib.h>
long long int hanno(int n);
long long int  tili(int n);
int main()
{
    int n ;
    scanf("%d",&n);


 printf("%lld",hanno(n));
    printf(" %lld",tili(n));


    return 0;
}
long long int hanno(int n)
{
    if(n==1)
    {
        return 1 ;
    }
    else
        return(hanno(n-1)*2+1);
}
long long int tili(int n)
{
    if(n==1)
    {
        return 1 ;
    }
    else
        return (tili(n-1)*2+n);

}


1: Note that the data type    

2: According to the law  

发布了19 篇原创文章 · 获赞 8 · 访问量 4148

Guess you like

Origin blog.csdn.net/paohui001lqp/article/details/79459093