【发布时间】:2012-10-21 13:43:12
【问题描述】:
我正在解决这个问题http://www.spoj.pl/problems/DISUBSTR/ 给定一个字符串,我们需要找到它的不同子字符串的总数。
Input
T- number of test cases. T<=20;
Each test case consists of one string, whose length is <= 1000
Output
For each test case output one number saying the number of distinct substrings.
Example
Sample Input:
2
CCCCC
ABABA
Sample Output:
5
9
Explanation for the testcase with string ABABA:
len=1 : A,B
len=2 : AB,BA
len=3 : ABA,BAB
len=4 : ABAB,BABA
len=5 : ABABA
Thus, total number of distinct substrings is 9.
我已经使用盲实现后缀数组解决了这个问题。但是,我想使用动态编程来解决它。但是我想不出任何方法来达到这个目的。时间复杂度需要为 0(n*n) 或更快。请任何人都可以指导我正确的方向.任何提示/建议/伪代码将不胜感激。我已经考虑了很长时间,但想不出任何DP方法来解决问题?
【问题讨论】:
-
@DigitalDa:这是一个不同的问题
-
@DanielFisher:我不明白
-
为什么要应用动态规划?
-
@alestanis:这几天我在练习DP问题。
标签: c++ algorithm logic dynamic-programming