Total prefix COUNT = number of prefix categories + number of occurrences of each prefix after
A good question is posted, but the question is not very clear. That's why next [J] + 1 = next [J + 1] is not counted?
Http://972169909-qq-com.iteye.com/blog/1114968
If next is equal to the next value plus one, this statistics will be calculated later, so ignore
# Include <stdio. h> # include <string. h> # define Val 200005int next [Val], lenp; char P [Val]; void set_next (); int main () {int cas, I, ans; for (scanf ("% d", & CAS); CAS --) {scanf ("% d", & lenp); scanf ("% s", P ); set_next (); ans = lenp + next [lenp]; for (I = lenp-1; I> = 1; I --) if (next [I]! = Next [I + 1]-1) ans + = next [I]; printf ("% d \ n", ANS % 10007);} return 0 ;} void set_next () {int K, J; k =-1, j = 0; next [J] = K; while (j <lenp) {If (k =-1 | P [J] = P [k]) {k ++; j ++; next [J] = K ;} else K = next [k] ;}}