Блог пользователя Monster_Nerd

Автор Monster_Nerd, история, 4 года назад, По-английски

Recently i encountered TLE on this problem E. Tree-String Problem
using decent dfs + kmp. Later i came to know that there is an optimized version of kmp. I listed the code below which i had taken from Arpa 's code.

int k = 0;
    for(int i = 1; i < p.size(); i++){
	while(k && p[i] != p[k]) k = f[k];
	if(p[i] == p[k])  k++;
	f[i + 1] = k;
    }

for(int i = 0; i < p.size(); i++)
	for(int j = 0; j < z; j++)
	    nxt[i][j] = p[i] - 'a' == j ? i + 1 : bool(i) * nxt[ f[i] ][j];

now my question is, can i use it always [if memory limit is ok] ? Does it consistent and can anyone just briefly explain what does it do?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +23
  • Проголосовать: не нравится