https://acs.jxnu.edu.cn/problem/GYM100002B
Bill is trying to compactly represent sequences of capital alphabetic characters from 'A' to 'Z' by folding repeating subsequences inside them. For example, one way to represent a sequence AAAAAAAAAABABABCCD is 10(A)2(BA)B2(C)D. He formally defines folded sequences of characters along with the unfolding transformation for them in the following way:
- A sequence that contains a single character from 'A' to 'Z' is considered to be a folded sequence. Unfolding of this sequence produces the same sequence of a single character itself.
- If S and Q are folded sequences, then SQ is also a folded sequence. If S unfolds to S' and Q unfolds to Q', then SQ unfolds to S'Q'.
- If S is a folded sequence, then X(S) is also a folded sequence, where X is a decimal representation of an integer number greater than 1. If S unfolds to S', then X(S) unfolds to S' repeated X times.
According to this definition it is easy to unfold any given folded sequence. However, Bill is much more interested in the reverse transformation. He wants to fold the given sequence in such a way that the resulting folded sequence contains the least possible number of characters.
Input
The input file contains a single line of characters from 'A' to 'Z' with at least 1 and at most 100 characters.
Output
Write to the output file a single line that contains the shortest possible folded sequence that unfolds to the sequence that is given in the input file. If there are many such sequences then write any one of them.
Sample input and output
folding.in | folding.out |
AAAAAAAAAABABABCCD |
9(A)3(AB)CCD |
NEERCYESYESYESNEERCYESYESYES |
2(NEERC3(YES)) |
题目大意:
比尔正试图通过在其中折叠重复的子序列来简洁地表示从“A”到“Z”的大写字母字符序列。例如,AAAAAAAAAABABABCCD 一种表示顺序的方法是10(A)2(BA)B2(C)D。他用以下方式正式定义了字符的折叠序列及其展开变换:
包含从‘A’到‘Z’的单个字符的序列被认为是折叠序列。
如果S和Q是折叠序列,那么SQ也是折叠序列。如果S向S‘展开,q展开为q’,则SQ向s‘q’展开。
如果S是折叠序列,那么X(S)也是折叠序列,其中X是十进制。大于1.lfS的整数的表示为S‘,则X(S)展开为s’重复的X次。
根据这一定义,任何给定的折叠顺序都很容易展开,但比尔对反向转换更感兴趣,他想用这样的方式折叠给定的序列,使所产生的折叠序列包含尽可能少的字符。
输入
输入文件包含从‘A’到‘Z’的一行字符,其中至少有1个字符,最多100个字符。
输出
向输出文件写入一行,其中包含尽可能最短的折叠序列,该序列将显示到输入文件中给定的序列。如果有很多这样的序列,那就写其中任何一个。
样本实例
folding.in | folding.out |
AAAAAAAAAABABABCCD |
9(A)3(AB)CCD |
NEERCYESYESYESNEERCYESYESYES |
2(NEERC3(YES)) |