AC自动机的实现原理是KMP + 字典树。 学AC自动机之前要先去学KMP 和 字典树。

 

第一步先构建一个字典树。

 1 void Insert(){
 2     int rt = 1, len = strlen(str);
 3     for(int i = 0; i < len; i++){
 4         int id = str[i] - 'a';
 5         if(trie[rt][id] == 0){
 6             cnt[tot] = 0;
 7             fair[tot] = 0;
 8             trie[rt][id] = tot++;
 9         }
10         rt = trie[rt][id];
11     }
12     cnt[rt]++;
13 }
插入字典树

相关文章:

  • 2021-10-25
  • 2021-10-23
猜你喜欢
  • 2021-11-28
  • 2021-11-30
  • 2021-11-03
  • 2021-08-28
  • 2021-08-13
  • 2022-01-09
  • 2021-11-30
相关资源
相似解决方案