My Carelessness

Back to your page!


Or leave your comments here.

RegendLa

导航

关于简单汉诺塔

  问:求n层汉诺塔至少需要多少步完成。

  

#include<stdio.h>
int f(int n);
int main()
{
	int n;
	scanf("%d",&n);
	printf("%d层汉诺塔至少需要%d步\n",n,f(n));
	return 0;
}
int f(int n)
{
	if(n==1)
		return 1;
	else	
		return 2*f(n-1)+1;
}

  

posted on 2015-05-11 17:36  最爱七  阅读(207)  评论(0编辑  收藏  举报




Thanks for your coming!
If what you read helps,I would appreciate!