#P2470. [SCOI2007] 压缩

    ID: 1481 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串动态规划,dp2007四川各省省选区间 dp

[SCOI2007] 压缩

Description

Given a string consisting of lowercase letters, we can compress its repeated information using a simple method. The compressed string may (but does not have to) contain uppercase letters R\texttt{R} and M\texttt{M} in addition to lowercase letters, where M\texttt{M} marks the start of a repeated segment, and R\texttt{R} repeats the decompressed result starting from the previous M\texttt{M} (if there is no M\texttt{M} to the left of the current position, start from the beginning of the string), which is called the buffer string.

bcdcdcdcd\texttt{bcdcdcdcd} can be compressed as bMcdRR\texttt{bMcdRR}. The decompression process is shown below:

Already decompressed part Decompression result Buffer string
b\texttt{b} b\texttt{b} b\texttt{b}
bM\texttt{bM} .\texttt{.}
bMc\texttt{bMc} bc\texttt{bc} c\texttt{c}
bMcd\texttt{bMcd} bcd\texttt{bcd} cd\texttt{cd}
bMcdR\texttt{bMcdR} bcdcd\texttt{bcdcd} cdcd\texttt{cdcd}
bMcdRR\texttt{bMcdRR} bcdcdcdcd\texttt{bcdcdcdcd} cdcdcdcd\texttt{cdcdcdcd}

Input Format

The input contains a single line with the string to compress, consisting only of lowercase letters, of length nn.

Output Format

Output a single line: the minimum possible length of the compressed string.

aaaaaaa
5
bcdcdcdcdxcdcdcdcd
12

Hint

In the first example, an answer is aaaRa\texttt{aaaRa}. In the second example, an answer is bMcdRRxMcdRR\texttt{bMcdRRxMcdRR}.

Constraints

  • For 50%50\% of the testdata, 1n201\le n \le 20.
  • For 100%100\% of the testdata, 1n501\le n \le 50.

Translated by ChatGPT 5