当前位置:网站首页>Problem C: Hanoi Tower III
Problem C: Hanoi Tower III
2022-04-23 03:22:00 【Tang Encheng_ hhhc】
Problem C: Hanoi Ⅲ
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 799 Solved: 566
Description
Hanoi ( Also known as the river tower ) The problem is a puzzle toy from an ancient Indian legend . Vatican made three diamond pillars when he created the world , Stack on a column from bottom to top in order of size 64 A golden disk . Brahman ordered Brahman to rearrange the disc from below on another pillar in order of size . And stipulate , You can't enlarge a disc on a small disc , Only one disc can be moved between the three pillars at a time .
Those intelligence questions always require people to complete the requirements in the questions with the least steps . Why the least ? Let's have something special this time , I hope your program can meet the requirements with the most steps , And there is no repetition of any state in this process .
Please associate the Hanoi Tower knowledge you have learned .
Input
The input contains multiple sets of data tests , Each set of data has only the number of discs n( 1 <= n <= 12)
Output
For each group, the number of times the plate meets the conditions is the most
Sample Input
1
3
12
Sample Output
2
26
531440
#include <stdio.h>
int tower(int n);
int main()
{
int n;
while (scanf("%d",&n) != EOF)
{
printf("%d\n",tower(n));
}
return 0;
}
// Use recursion as at least , But the first plate is first A->B,A->C, So the following recursion should be the same
int tower(int n)
{
int sum = 0;
if (n == 1)
{
sum+=2;// Two steps for the first plate
return sum;
}
else
{
sum += tower(n-1);
sum ++;
sum += tower(n-1);
sum++;
sum += tower(n-1);
}
return sum;
}
版权声明
本文为[Tang Encheng_ hhhc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621319853.html
边栏推荐
- MySql关键字GROUP_CONCAT,组合连接查询
- 2022 Shandong Province safety officer C certificate work certificate question bank and online simulation examination
- Seminar playback video: how to improve Jenkins' ability to become a real Devops platform
- JS, bind the event for a label with input, and then bind the stand-alone event in the parent element. The event is executed twice and solved
- Supersocket is Use in net5 - startup
- Preview of converting doc and PDF to SWF file
- Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
- Detailed description of MySQL index [B + tree index, hash index, full-text index, overlay index]
- [Mysql] LEFT函数 | RIGHT函数
- xutils3修改了我提报的一个bug,开心
猜你喜欢
. net 5 Web custom middleware implementation returns the default picture
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
手机连接电脑后,QT的QDIR怎么读取手机文件路径
一套组合拳,打造一款 IDEA 护眼方案
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
2022g2 boiler stoker examination question bank and online simulation examination
【无标题】
2022G2电站锅炉司炉考试题库及在线模拟考试
ASP. Net 6 middleware series - conditional Middleware
随机推荐
《C语言程序设计》(谭浩强第五版) 第8章 善于利用指针 习题解析与答案
LoadRunner - performance testing tool
[MySQL] left function | right function
. net core current limiting control - aspnetcoreratelimit
QT learning summary
A set of combination boxing to create an idea eye protection scheme
Find the number of leaf nodes of binary tree
为什么BI对企业这么重要?
Mysql database design specification
WinForm allows the form form to switch between the front and active states
QT dynamic translation of Chinese and English languages
Docker拉取mysql并连接
It can receive multiple data type parameters - variable parameters
Experiment 6 input / output stream
Xutils3 corrected a bug I reported. Happy
Idempotency practice operation, explaining idempotency based on business
Ide-idea-problem
Charles uses three ways to modify requests and responses
Can you answer the questions that cannot be answered with a monthly salary of 10k-20k?
2022 P cylinder filling training test questions and simulation test