luogu#P5189. [COCI 2009/2010 #5] ZUMA
[COCI 2009/2010 #5] ZUMA
Problem Description
Translated from COCI 2010.03.06 Task 4 “ZUMA”.
Mirko lines up marbles in a row, numbered in order. The color of marble is . He discovered that if he touches consecutive marbles and all of them have the same color, magic will make these marbles disappear; after that, the marbles before these marbles become adjacent to the marbles after these marbles.
Mirko has many marbles at home. He wants to insert as few marbles as possible among these marbles (he may also insert marbles before the first marble or after the last marble) so that all of the original marbles plus all inserted marbles disappear.
Input Format
The first line contains .
The second line contains .
Output Format
One line with one integer, the minimum number of marbles he needs to insert.
2 5
1 1
3
5 3
2 2 3 2 2
2
10 4
3 3 3 3 2 3 1 1 1 3
4
Hint
Constraints: , , .
Translated by ChatGPT 5