#P14817. [ICPC 2023 Yokohama R] Nested Repetition Compression

    ID: 16632 远端评测题 2000ms 2048MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2023Special Judge区间 DPICPC横浜

[ICPC 2023 Yokohama R] Nested Repetition Compression

题目描述

You have a number of strings of lowercase letters to be sent in e-mails, but some of them are so long that typing as they are would be tiresome. As you found repeated parts in them, you have decided to try out a simple compression method in which repeated sequences are enclosed in parentheses, prefixed with digits meaning the numbers of repetitions. For example, the string “abababaaaaa” can be represented as “3(ab)5(a)” or “a3(ba)4(a)”. The syntax of compressed representations is given below in Backus-Naur form with the start symbol SS.

$$\begin{aligned} &\langle S \rangle ::= \langle R \rangle \mid \langle R \rangle \langle S \rangle \\ &\langle R \rangle ::= \langle L \rangle \mid \langle D \rangle \ (\langle S \rangle) \\ &\langle D \rangle ::= 2 \mid 3 \mid 4 \mid 5 \mid 6 \mid 7 \mid 8 \mid 9 \\ &\langle L \rangle ::= \text{a} \mid \text{b} \mid \text{c} \mid \text{d} \mid \text{e} \mid \text{f} \mid \text{g} \mid \text{h} \mid \text{i} \mid \text{j} \mid \text{k} \mid \text{l} \mid \text{m} \mid \text{n} \mid \text{o} \mid \text{p} \mid \text{q} \mid \text{r} \mid \text{s} \mid \text{t} \mid \text{u} \mid \text{v} \mid \text{w} \mid \text{x} \mid \text{y} \mid \text{z} \end{aligned}$$

Note that numbers of repetitions are specified by a single digit, and thus at most nine, but more repetitions can be specified by nesting them. A string of thirty a’s can be represented as “6(5(a))” or “3(5(2(a)))”, for example.

Find the shortest possible representation of the given string in this compression scheme.

输入格式

The input is a line containing a string of lowercase letters. The number of letters in the string is at least one and at most 200.

输出格式

Output a single line containing the shortest possible representation of the input string. If there exist two or more shortest representations, any of them is acceptable.

abababaaaaa
3(ab)5(a)
abababcaaaaaabababcaaaaa
2(3(ab)c5(a))
abcdefg 
abcdefg