#P4170. [CQOI2007] 涂色

    ID: 3101 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串2007重庆各省省选枚举,暴力区间 dp

[CQOI2007] 涂色

Description

Suppose you have a wooden board of length 55, initially unpainted. You want to paint its 55 unit segments red, green, blue, green, and red, respectively, represented by a length-55 string: RGBGR\texttt{RGBGR}.

Each time, you may paint a consecutive segment of the board with a given color, and later paint covers earlier paint. For example, first paint RRRRR\texttt{RRRRR}, then paint RGGGR\texttt{RGGGR}, and finally paint RGBGR\texttt{RGBGR} to reach the target.

Use as few painting operations as possible to reach the target.

Input Format

The input contains a single line with a string of length nn, which is the painting target. Every character is an uppercase letter; different letters denote different colors, and the same letters denote the same color.

Output Format

Output a single line with one number: the minimum number of painting operations.

AAAAA
1
RGBGR
3

Hint

40%40\% of the testdata satisfies 1n101 \le n \le 10.

100%100\% of the testdata satisfies 1n501 \le n \le 50.

Translated by ChatGPT 5