题意:容易理解...
分析:在做这道题之前我做了hdu 4057,都是同一种类型的题,因为题中给的模式串的个数最多只能为10个,所以我们就很容易想到用状态压缩来做,但是开始的时候我的代码超时了dp时我们由dp[i][j][k]枚举其后接的字符转移到dp[i+1],在枚举前判断下是否有dp[i][j][k]=0,是的话可以直接continue,而不用再深一层循环.这样优化之后就没超时了。我用了滚动数组实现,其实这题可以不用滚动数组也可以过的,空间上不会卡。
代码实现:
#include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<queue> #include<cmath> #include<algorithm> using namespace std; struct node{ int next[26]; int fail; int flag; void init() { memset(next,0,sizeof(next)); fail=0; flag=0; } }a[105]; char keyword[15]; int tot,n,m,len; int dp[2][105][1<<10]; void chushihua() { tot=0; a[0].init(); memset(dp,0,sizeof(dp)); } void insert(char *str,int biaohao) { int index,p=0; for(;*str!='