2019 Java Chapter 18 (Week 14)

From: 2019-09-04 00:00:00 To: 2019-12-31 00:00:00 Now: 2024-11-21 21:46:08 Status: Public

C - Tower of Hanoi

Time Limit: 1s Memory Limit: 128MB

Submissions: 118 Solved: 83
Description

(하노이의 탑) 18.8의 TowerOfHanoi.java를 수정하여, n개 원판들이 A탑에서 B탑으로 이동하는 횟수를 구하시오.

(힌트 : 정적 변수를 사용하여, 함수가 호출될 때마다 증가시키시오.)

(힌트2 : 하노이의 탑 원본은 3개의 탑에 대한 문제입니다.)

(Tower of Hanoi) Modify Listing 18.8, TowerOfHanoi.java, so that the program finds the number of moves needed to move n disks from tower A to tower B.

(Hint: Use a static variable and increment it every time the method is called.)

(Hint2 : Original Tower of Hanoi problem is question about 3 tower)

Input

* Line 1 :  테스트 케이스 T (1~1,000)

* Line 2 ~ T+1 : n (1~20)

Output

* Line 1 ~ T : n개 원판들의 이동 횟수

Sample Input
3
9
20
7
Sample Output
117
116515
31
Source

JAVA2015 PE18.18