AC自动机总结
AC自动机的模板
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 void buildAC() 2 { 3 while(!q.empty()) q.pop(); 4 q.push(0); 5 while(!q.empty()) 6 { 7 int x=q.front();q.pop(); 8 int fail=a[x].fail; 9 for(int i=0;i<=1;i++) 10 { 11 if(a[x].son[i]) 12 { 13 a[a[x].son[i]].fail=x ? a[fail].son[i] : 0;//直接push根就要判断(根的孩子的fail=根) 14 q.push(a[x].son[i]); 15 } 16 else a[x].son[i]=a[fail].son[i]; 17 } 18 } 19 } 20 21 void buildAC() 22 { 23 while(!q.empty()) q.pop(); 24 for(int i=1;i<=S;i++) 25 if(a[0].son[i]) q.push(a[0].son[i]); 26 while(!q.empty()) 27 { 28 int x=q.front();q.pop(); 29 int fail=a[x].fail; 30 for(int i=1;i<=S;i++) 31 { 32 if(a[x].son[i]) 33 { 34 a[a[x].son[i]].fail=a[fail].son[i];//push根的孩子就不用这一步 35 q.push(a[x].son[i]); 36 } 37 else a[x].son[i]=a[fail].son[i]; 38 } 39 } 40 }
LA3942 http://www.cnblogs.com/KonjakJuruo/p/5686373.html
uva11732 http://www.cnblogs.com/KonjakJuruo/p/5686380.html
hdu2222 http://www.cnblogs.com/KonjakJuruo/p/5686398.html
hdu1251 http://www.cnblogs.com/KonjakJuruo/p/5686407.html
LA4670 http://www.cnblogs.com/KonjakJuruo/p/5686416.html
uva11468 http://www.cnblogs.com/KonjakJuruo/p/5686437.html
uva11019 http://www.cnblogs.com/KonjakJuruo/p/5686442.html
bzoj2434 http://www.cnblogs.com/KonjakJuruo/p/5662749.html
hdu3247 http://www.cnblogs.com/KonjakJuruo/p/5665829.html
hdu3341 http://www.cnblogs.com/KonjakJuruo/p/5667099.html
LA5766/uva1502/hdu4117 http://www.cnblogs.com/KonjakJuruo/p/5680063.html
hdu3065 http://www.cnblogs.com/KonjakJuruo/p/5686451.html
poj3208 http://www.cnblogs.com/KonjakJuruo/p/5673525.html
poj2778 http://www.cnblogs.com/KonjakJuruo/p/5669576.html
hdu2825 http://www.cnblogs.com/KonjakJuruo/p/5686456.html