Problem Description
give you a string, please output the result of the following function mod 1000000007
n is the length of the string
f() is the function of fibonacci, f(0) = 0, f(1) = 1...
a[i] is the total number of times any prefix appear in the suffix s[i....n-1].
(the prefix means s[0...i] )
解法:如果知道了num[i]表示i開始的後綴s[i....n]跟前綴s[1...]之間的公共的前綴,那麼以i開頭的後綴中就匹配了num[i]個前綴了
所以i這個後綴出現的前綴的數量實際上就是num[i] + num[i+1] + .. num[n]. 求出來之後快速冪求斐波那契數列相應項大小即可。求lcp的時候是二分+hash;字符串hash中,seed為31(java庫源碼中是這個數,應該是效果比較好的)
代碼:
/******************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
#include
#include
#include
#include