AC自动机模板
2016-03-02 15:49
375 查看
啦啦啦二十分钟默出来编译通过,一会去试几道题好啦
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn = 10005; const int maxm = 100; int n, tot, temp; int ch[maxn][maxm], fail[maxn], flag[maxn], q[maxn]; int cal(char c) { return c-'a'; } void newnode(int x,int temp) { ch[x][temp] = ++tot; //还有别的我懒得写2333333 } void addtrie(char s[]) { int x = 0, p = 0; int len = strlen(s); while( p < len ) { temp=cal(s[p]); if( !ch[x][temp] ) newnode(x, temp); x = ch[x][temp]; p++; } flag[x] = true; } void getfail(void) { int h = 0, t = 0; for(int i = 0; i < maxm; i++) if( ch[0][i] ) q[t++] = ch[0][i]; while( h < t ) { temp=q[h++]; //flag[temp]|=flag[fail[temp]]; for(int i = 0; i < maxm; i++) if( !ch[temp][i] ) ch[temp][i] = ch[fail[temp]][i]; else { q[t++] = ch[temp][i]; fail[ch[temp][i]] = ch[fail[temp]][i]; } } } int main(void) { return 0; }
相关文章推荐
- 迭代器
- Cordova 系列之Mac OS 环境配置
- MongoDB添加用户
- json 语法
- RNN 入门教程 Part 4 – 实现 RNN-LSTM 和 GRU 模型
- DrawerLayoutAndroid如何通过点击事件打开
- UITableable代理执行的顺序
- android studio 学习笔记
- Exchange2013/2016 ECP/OWA无法打开主页Event 1310 Net 4.0
- 机器学习一小步:Kaggle上的练习Titanic: Machine Learning from Disaster(二)
- Android应用启动后自动创建桌面快捷方式
- window遍历文件夹下的文件 http://bbs.csdn.net/topics/390368005/
- MyEclipse配置Tomcat没有Tomcat选项没有小猫图
- Vim使用笔记
- Rabbitmq 开发说明
- js获取所点击<a>的href值
- C++第一次实验
- 【转】解释器模式
- 滚来滚去,滚来滚去...Scroller完全解析
- 技术学习论坛地址收集