【后缀自动机】CodeForces 123D String
通道:http://codeforces.com/problemset/problem/123/D
题意:定义F(s,x)表示s中的子串的子串等于x的有多少个,求和,例如,F(babbabbababbab, babb) = 6. The list of pairs is as follows:(1, 4), (4, 7), (9, 12),会产生
- (1, 4)
- (4, 7)
- (9, 12)
- (1, 4), (4, 7)
- (4, 7), (9, 12)
- (1, 4), (4, 7), (9, 12) 所以对于状态babb是6,求总和
思路:直接SAM,然后把每一段[val[fa[i]]+1, val[i]]×num[i]*(num[i] + 1)/2即可,num[i]表示I节点往下走有多少条路径
代码:https://github.com/Mithril0rd/Rojo/blob/master/cf123d.cpp
TAG:SAM