#P5971. [CTSC2009] 移盘子
[CTSC2009] 移盘子
Description
There are three pegs, named , , and . Initially, has plates on it, while and are empty. Each move consists of taking the top plate from one peg and placing it onto another peg. Plates are of three types, denoted by , , and . Your goal is to have all type plates on , all type plates on , and all type plates on in the end. Find the minimum number of moves needed to achieve this goal.
Input Format
The input file trique.in contains:
- The first line: an integer , the total number of plates.
- The second line: numbers, each being , , or . These numbers describe the types of all plates initially on peg , listed from top to bottom.
Output Format
The output file trique.out contains a single number: the minimum number of moves.
5
1 2 1 3 3
8
Hint
Sample explanation:
Initial state as shown below:

Constraints:
- For % of the testdata, the number of plate types does not exceed .
- For % of the testdata, .
- For % of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号