#P1096. [NOIP 2007 普及组] Hanoi 双塔问题

    ID: 96 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学高精度递推2007递归NOIp 普及组

[NOIP 2007 普及组] Hanoi 双塔问题

Description

Given three sufficiently long thin pegs A, B, and C, there are 2n2n disks with holes on peg A. There are nn distinct sizes, and for each size there are two identical disks; note that these two disks are indistinguishable (the figure below shows the case n=3n=3).

We need to move all these disks to peg C, and disks may be temporarily placed on peg B during the process. Requirements:

  1. Only one disk may be moved at a time.
  2. On pegs A, B, and C, the disks must always keep the order of smaller on top and larger below.

Task: Let AnA_n be the minimum number of moves required to complete the task for 2n2n disks. For the given nn, output AnA_n.

Input Format

A positive integer nn, indicating there are 2n2n disks on peg A.

Output Format

A positive integer, which is the minimum number of moves AnA_n required to complete the task.

1
2
2
6

Hint

Constraints

  • 对于 50%50\% 的数据,1n251 \le n \le 25
  • 对于 100%100\% 的数据,1n2001 \le n \le 200

Hint

Try to establish a recurrence relation between AnA_n and An1A_{n-1}.

Translated by ChatGPT 5