后缀自动机秒题。
首先观察公式,发现它最难的地方在求所有后缀的LCP之和。
首先回想一下求两个后缀的LCP怎么搞?
先翻转原串,然后在fail树上找到它们的LCA,LCA节点的step值即为它们的最长公共前缀。
延续这个思路,将问题转化成,给定一颗树,每个节点上有一个权值,现在有很多特殊点,一对特殊点的权值为它们LCA的权值,求所有点对的权值和。
树形dp秒之。
#include #include #include #include #include #include #include #include #include #include #include