双数组AC自动机(doubleArrayTrie)的实现

按照PPT上的描述写了个最简单的版本,没敢测大数据。

主要是几个表的构建:

首先构建next,base,check表。

根据失效函数的定义:父状态的失效函数输入当前字符,可得出每个状态的失效函数(要转移到的状态)

可以发现每个状态要转移到的状态是一定的,如下图:

所以可以构造一个fail表,由上述三个表来构建。

为了输出方便,又构造了一个output表。

代码如下:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

struct node
{
    int currentCharacter;
    int fatherCharacter;
} modelSet[100][100];

struct nextNode
{
    int state;
    int character;
} next[256];

struct outputNode
{
    int state;
    char str[100];
    bool available;
} output[256];

struct zhongyu
{
    int pos;
    int state;
}result[100];

queue<int>q;
int characterAppear[256];
int base[256];
int check[256];
int fail[256];
int currentState=0;
int fatherState=0;

int readyToInsert[256];
int index=0;
int curNodeNum=0;
int nextNodeNum=0;
int inputNum;
char input[100][100];
int tongji=0;
int currentPos;

void buildTable();
int gotoFunc(int state,int c);
void buildFailTable();
void buildOutputTable();

int main()
{
    freopen("1.txt","r",stdin);
    memset(input,0,sizeof(input));
    scanf("%d",&inputNum);
    int rowLen;
    int maxRowLen=-1;
    for(int i=0; i<inputNum; i++)
    {
        scanf(" %s",input
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值