题解 | #大吉大利,今晚吃鸡#

大吉大利,今晚吃鸡

https://www.nowcoder.com/practice/c9d9f9c60b4448eabc0569f80a3461bb

#include<stdio.h>
int test(int x)
{
	if (x == 1)
	{
		return 2;

	}
	else
	{
		return test(x - 1) + 2 * test(x - 1) + 2;//多做几次试验发现,可以把问题拆解为把最下面的第n个圆盘放到c柱,再把上面n-1个圆盘放到c柱,而把最下面的第n个圆盘放到c柱次数=两倍的把上面n-1个圆盘放到c柱次数+2
	}
}

int main()
{
	int n = 0;
	while (scanf("%d", &n) != EOF)
	{
		int ret = test(n);
		printf("%d\n", ret);
	}
	return 0;

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务