CF1572C Paint
题目描述
给定长度为 $n$ 的颜色序列 $a_i$,每次你可以选择任意长度的**连续且颜色相同**的一段位置,将其全部变成任意同一种颜色,问你最少总共需要多少次操作才能使得整个序列颜色相同。
**限制:** 每一种颜色初始时在序列中最多只有20个位置(是该种颜色)。
输入格式
无
输出格式
无
说明/提示
In the first example, the optimal solution is to apply the operation on the third pixel changing its color to $ 2 $ and then to apply the operation on any pixel that has color $ 2 $ changing its color and the color of all pixels connected to it to $ 1 $ . The sequence of operations is then: $ [1, 2, 3, 2, 1] \to [1, 2, 2, 2, 1] \to [1, 1, 1, 1, 1] $ .
In the second example, we can either change the $ 1 $ s to $ 2 $ s in one operation or change the $ 2 $ s to $ 1 $ s also in one operation.
In the third example, one possible way to make all the pixels have the same color is to apply the operation on the first, third and the fourth pixel each time changing its color to $ 2 $ .