bzoj1212: [HNOI2004]L语言
2017-04-08 15:54
323 查看
传送门
对于被匹配的串暴力建立trie
然后直接每个位置往下匹配就行了。
对于被匹配的串暴力建立trie
然后直接每个位置往下匹配就行了。
#include<cstring> #include<cmath> #include<cstdio> #include<iostream> #include<cstdlib> #include<algorithm> using namespace std; char s[15],str[1050005]; int f[1050005],n,m,len,now,ch[305][30],bo[305],tot,ans,t; inline void updata(int x){ int now=ch[0][str[x]-'a']; for (;now;now=ch[now][str[++x]-'a']){ if (bo[now]) f[x]=1; if (x==len) return; } } int main(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;i++){ scanf("%s",s+1); len=strlen(s+1); now=0; for (int j=1;j<=len;j++){ if (!ch[now][s[j]-'a']) ch[now][s[j]-'a']=++tot; now=ch[now][s[j]-'a']; } bo[now]=1; } for (int i=1;i<=m;i++){ scanf("%s",str+1); len=strlen(str+1); ans=t=0; memset(f,0,sizeof(f)); f[0]=1; for (int j=0;j<=len;j++){ if (t>10) break; if (!f[j]){ t++; continue; } ans=j; t=0; updata(j+1); } printf("%d\n",ans); } }
相关文章推荐
- BZOJ1212 [HNOI2004]L语言
- [bzoj1212] [HNOI2004]L语言(trie+dp)
- Bzoj1212: [HNOI2004]L语言
- [DP+AC自动机] BZOJ1212: [HNOI2004]L语言
- Bzoj 1212: [HNOI2004]L语言(AC自动机+DP)
- [bzoj1212][HNOI2004]L语言_AC自动机_动态规划
- [BZOJ1212][HNOI2004]L语言(AC自动机+dp)
- BZOJ_1212_[HNOI2004]L语言_哈希
- bzoj 1212 [HNOI2004]L语言
- bzoj1212: [HNOI2004]L语言
- bzoj 1212: [HNOI2004]L语言 AC自动机+状压
- BZOJ 1212: [HNOI2004]L语言( dp + trie )
- BZOJ 1212: [HNOI2004]L语言 AC自动机
- BZOJ 1212 HNOI 2004 L语言 Trie树
- [HNOI2004][bzoj1212] L语言 [Trie+dp]
- 【BZOJ1212】[HNOI2004]L语言 Trie树
- [BZOJ1212]-[HNOI2004]L语言-trie+DP
- BZOJ1212: [HNOI2004]L语言 AC自动机
- BZOJ 1212: [HNOI2004]L语言 [AC自动机 DP]
- BZOJ 1212 HNOI2004 L语言 AC自动机(Trie树)+动态规划