Color ribbon - MarisaOJ: Marisa Online Judge

Color ribbon

Time limit: 1000 ms
Memory limit: 256 MB
Given a ribbon of length $n$. You can paint a continuous segment on the ribbon with one of 26 colors corresponding to lowercase letters. Initially, the ribbon has no color. Find the way to use the fewest number of painting operations so that the ribbon has the color pattern corresponding to the string $S$. ### Input - A single line containing the string $S$ consisting only of lowercase letters of length $n$. ### Output - Output an integer representing the minimum number of painting operations. ### Constraints - $1 \le n \le 1000$. ### Example Input: ``` abcba ``` Output: ``` 3 ``` Explanation: - The first painting colors `a` from position $1$ to $5$: `aaaaa`. - The second painting colors `b` from position $2$ to $4$: `abbba`. - The third painting colors `c` at position $3$: `abcba`.