hdu 2896 病毒侵襲 ac自動機

2021-09-20 13:47:09 字數 1750 閱讀 2143

/*

hdu 2896 病毒侵襲 ac自動機 

從題意得知,模式串中沒有重複的串出現,所以結構體中可以將last(字尾鏈結)陣列去掉 

last陣列主要是記錄具有相同字尾模式串的末尾節點編號 。本題中主要是計算每乙個模式串

在主串中有沒有出現過,而不是計算出現過多少次,所以將last陣列省掉.... 

*/ #include

#include

#include

#include

#include

#define n 210*500

using namespace std;

class ac_atomata

void build(char *str, int index);//建立trie樹 

void getfail();//失配函式 

void find(char *t, int n, int index);//查詢函式 

};void ac_atomata::build(char *str, int index)

u=trie[u][ch];

val[u]=0; }

val[u]=index; }

void ac_atomata::getfail()

} while(!q.empty())

} }

void ac_atomata::find(char *t, int n, int index)

} if(cnt>0)

} ac_atomata ac;

char t[10005], s[205];

int main()

ac.getfail();

scanf("%d", &m);

for(i=1; i<=m; ++i)

printf("total: %d\n", ac.total); }

return 0;

} /*

上面的程式過了,感覺資料很水....

*/#include

#include

#include

#include

#define n 100005 

#define m 505

using namespace std;

int n, m;

class ac_atomata ;

void ac_atomata:: init()

void ac_atomata:: build(char *t, int index)

val[u]=0;

u=trie[u][t[i]]; }

val[u]=index; }

void ac_atomata:: getfail()

} while(!q.empty())

void ac_atomata:: find(char *s, int index)

next=fail[next];

}  }

if(count>0)

char t[205], s[10005];

ac_atomata ac;

int main()

ac.getfail();

scanf("%d", &m) ;

for(i=1; i<=m; ++i)

printf("total: %d\n", ac.cnt); }

return 0; }

hdu 2896 病毒侵襲 AC自動機

hdu 2896 題目大意 給出n個模式串,最後給出m個主串 問有主串出現過哪些模式串,最後輸出哪些主串能匹配模式串 解題思路 ac自動機建立字典樹的用w值標記第幾個模式串 定義k值,匹配時若字典樹中的某個結點不等於k且w不為0則記錄該點 有多個主串需要匹配,所以不需要改變w的值,但可以判斷k的值 ...

hdu 2896 病毒侵襲 ac自動機

include include include using namespace std define maxnode 100100 define sigma size 135 int ch maxnode sigma size int f maxnode fail函式 int val maxnode...

AC自動機 病毒侵襲 hdu2896

和hdu2222題相似的水題 1 連著re了好多發,沒想明白,看了一下網上題解才知道,輸入的不一定都是字母,所以next要開100!include include int tot char str 10005 int t int time 100 struct trie queue 100005 s...