当前位置:网站首页>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
边栏推荐
- Chapter 7 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of modular programming exercises with functions
- Docker拉取mysql并连接
- EasyUI's combobox implements three-level query
- PID debugging of coding motor (speed loop | position loop | follow)
- Build websocket server in. Net5 webapi
- After the mobile phone is connected to the computer, how can QT's QDIR read the mobile phone file path
- 手机连接电脑后,QT的QDIR怎么读取手机文件路径
- 研讨会回放视频:如何提升Jenkins能力,使其成为真正的DevOps平台
- JS inheritance
- js 中,为一个里面带有input 的label 绑定事件后在父元素绑定单机事件,事件执行两次,求解
猜你喜欢

2022G2电站锅炉司炉考试题库及在线模拟考试

Charles uses three ways to modify requests and responses

可以接收多种数据类型参数——可变参数

AWS from entry to actual combat: creating accounts

Xutils3 corrected a bug I reported. Happy

Course design of Database Principle -- material distribution management system
![[Mysql] LEFT函数 | RIGHT函数](/img/26/82e0f2280de011636c26931a74e749.png)
[Mysql] LEFT函数 | RIGHT函数

MySQL keyword group_ Concat, combined connection query

Student achievement management

Supersocket is Used in net5 - command
随机推荐
MySQL installation pit
socket编程 send()与 recv()函数详解
Experiment 6 input / output stream
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
Experiment 5 components and event handling
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
Improvement of ref and struct in C 11
The query type of MySQL is very inefficient.
Iotos IOT middle platform is connected to the access control system of isecure center
Super easy to use [general excel import function]
12.<tag-链表和常考点综合>-lt.234-回文链表
Xamarin effect Chapter 22 recording effect
集合之List接口
New ORM framework -- Introduction to beetlsql
Do you really understand hashcode and equals???
超好用的Excel异步导出功能
12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
Peut recevoir plusieurs paramètres de type de données - paramètres variables
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
Yes Redis using distributed cache in NE6 webapi