1. 程式人生 > >ACdream1430SETI(後綴自動機)

ACdream1430SETI(後綴自動機)

represent tput letters 位置 判斷 ppi num cab fin

問題:

Amateur astronomers Tom and Bob try to find radio broadcasts of extraterrestrial civilizations in the air. Recently they received some strange signal and represented it as a word consisting of small letters of the English alphabet. Now they wish to decode the signal. But they do not know what to start with.

They think that the extraterrestrial message consists of words, but they cannot identify them. Tom and Bob call a subword of the message a potential word if it has at least two non-overlapping occurrences in the message.

For example, if the message is “abacabacaba”, “abac” is a potential word, but “acaba” is not because two of its occurrences overlap.

Given a message m help Tom and Bob to find the number of potential words in it.

Input

Input file contains one string that consists of small letters of the English alphabet. The length of the message doesn’t exceed 10 000.

Output

Output one integer number — the number of potential words in a message.

Sample Input

abacabacaba

Sample Output

15

題意:

求字符串裏最長的不相交重復字串的長度。

思路;

後綴自動機,記錄每個狀態的最先出現和最後一次出現的位置,就可以判斷是否出現了多次,以及是否相交。

ACdream1430SETI(後綴自動機)