Problem
Given a length string formed over an alphabet of size , let the "substring count" denote the total number of distinct substrings of . Furthermore, let the "maximum substring count" denote the maximum number of distinct substrings that could appear in a string of length formed over .
The linguistic complexity of (written ) is equal to ; in other words, represents the percentage of observed substrings of to the total number that are theoretically possible. Note that , with smaller values of indicating that is more repetitive.
As an example, consider the DNA string () . In the following table, we demonstrate that by considering the number of observed and possible length substrings of , which are denoted by and , respectively. (Observe that and .)
给定长度 串 由字母组成 大小 ,让“子字符串计数” 表示的不同子字符串的总数 。此外,让“最大子串数” 表示可能出现在长度字符串中的最大不同子字符串数 形成 。
该语言复杂的 (书面 )等于 ; 换一种说法, 表示观察到的子字符串的百分比 达到理论上可能的总数。注意,具有较小的值 表明 更重复。
例如,考虑DNA字符串() 。在下表中,我们演示了 通过考虑观察到的数量和可能的长度 的子串 ,由表示 和 , 分别。(观察到 和 )
1 | 3 | 4 |
2 | 5 | 8 |
3 | 6 | 7 |
4 | 6 | 6 |
5 | 5 | 5 |
6 | 4 | 4 |
7 | 3 | 3 |
8 | 2 | 2 |
9 | 1 | 1 |
Total | 35 | 40 |
Given: A DNA string of length at most 100 kbp.
Return: The linguistic complexity .
给出: DNA字符串长度最多100kbp。
回报:语言的复杂性。
Sample Dataset
ATTTGGATT
Sample Output
0.875