atcoder#CODEFESTIVAL2017QUALAF. Squeezing Slimes
Squeezing Slimes
Score : points
Problem Statement
There are slimes lining up in a row. Initially, the sizes of the slimes are all .
Snuke can repeatedly perform the following operation.
- Choose a positive even number . Then, select consecutive slimes and form pairs from those slimes as follows: pair the -st and -nd of them from the left, the -rd and -th of them, , the -th and -th of them. Combine each pair of slimes into one larger slime. Here, the size of a combined slime is the sum of the individual slimes before combination. The order of the combined slimes remain the same as the pairs of slimes before combination.
Snuke wants to get to the situation where there are exactly slimes, and the size of the -th () slime from the left is . Find the minimum number of operations required to achieve his goal.
Note that is not directly given as input. Assume .
Constraints
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum number of operations required to achieve Snuke's goal.
2
3 3
2
One way to achieve Snuke's goal is as follows. Here, the selected slimes are marked in bold.
- (1, 1, 1, 1, 1, 1) → (1, 2, 2, 1)
- (1, 2, 2, 1) → (3, 3)
4
2 1 2 2
2
One way to achieve Snuke's goal is as follows.
- (1, 1, 1, 1, 1, 1, 1) → (2, 1, 1, 1, 1, 1)
- (2, 1, 1, 1, 1, 1) → (2, 1, 2, 2)
1
1
0
10
3 1 4 1 5 9 2 6 5 3
10