当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3572:Hanoi Towers

Special Judge 特殊评判
题目描述

The “Hanoi Towers” puzzle consists of three pegs (that we will name A, B, and C) with n disks of different diameters stacked onto the pegs. Initially all disks are stacked onto peg A with the smallest disk at the top and the largest one at the bottom, so that they form a conical shape on peg A.

A valid move in the puzzle is moving one disk from the top of one (source) peg to the top of the other (destination) peg, with a constraint that a disk can be placed only onto an empty destination peg or onto a disk of a larger diameter. We denote a move with two capital letters — the first letter denotes the source disk, and the second letter denotes the destination disk. For example, AB is a move from disk A to disk B.

The puzzle is considered solved when all the disks are stacked onto either peg B (with pegs A and C empty) or onto peg C (with pegs A and B empty). We will solve this puzzle with the following algorithm.

All six potential moves in the game (AB, AC, BA, BC, CA, and CB) are arranged into a list. The order of moves in this list defines our strategy. We always make the first valid move from this list with an additional constraint that we never move the same disk twice in a row.

It can be proven that this algorithm always solves the puzzle. Your problem is to find the number of moves it takes for this algorithm to solve the puzzle using a given strategy.

输入解释

The input file contains two lines. The first line consists of a single integer number n (1 ≤ n ≤ 30) — the number of disks in the puzzle. The second line contains descriptions of six moves separated by spaces — the strategy that is used to solve the puzzle.

输出解释

Write to the output file the number of moves it takes to solve the puzzle. This number will not exceed 1018.

输入样例
#13
AB BC CA BA CB AC
#22
AB BA CA BC CB AC
输出样例
#17
#25

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3572

最后修改于 2020-10-29T07:04:56+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000 65536