HDU 3065 病毒侵襲持續中 AC自動機

2021-10-02 12:04:46 字數 1090 閱讀 9021

題目大意:給出 n 個模式串和乙個文字串,問每個模式串在文字串中分別出現了多少次

題目分析:雖然暴跳fail也是可以實現這個題目的,但個人感覺更好的方法還是建立fail樹後在樹上dfs比較好,需要注意的就是mle的問題,因為這個題目是多組輸入,直接memset會卡記憶體,所以不妨自己寫乙個newnode函式,用多少初始化多少,比較方便

**:

#include#include#include#include#include#include#include#include#include#include#include#include#includeusing namespace std;

typedef long long ll;

const int inf=0x3f3f3f3f;

const int n=1e5+100;

char s[1010][60],str[2000100];

int fail[n],trie[n][130],rk[n],dp[n],cnt;

struct edge

edge[n];

int head[n],tot;

void addedge(int u,int v)

int newnode()

void insert_word(int id)

} while(!q.empty())

else

trie[cur][i]=trie[fail[cur]][i];

} }}int search_word()

}void dfs(int u)

}void init()

int main()

getfail();

scanf("%s",str);

search_word();

for(int i=1;i<=cnt;i++)

addedge(fail[i],i);

dfs(0);

for(int i=1;i<=n;i++)

if(dp[rk[i]])

printf("%s: %d\n",s[i],dp[rk[i]]); }

return 0;

}

hdu 3065 病毒侵襲持續中

題目大意及思路 ac自動機。include include include include include include include include include include includeusing namespace std define inf 0x3f3f3f3f define ...

HDU 3065 病毒侵襲持續中

這就更簡單了,都不用把out標記成false了 題目中的病毒都是大寫字母這個條件應該怎麼用?include include include include include include include include include include include include include ...

HDU 3065 病毒侵襲持續中

詢問每個模式串在文字傳中出現的次數。文字串中出現的字元不一定都是大寫字母,只需要在匹配的時候,對文字串進行特殊處理,將連續的大寫字母段當成合法的乙個文字串即可。然後 就是簡單的統計了。include include include include include include using name...