【Trie】bzoj1212 [HNOI2004]L语言
2015-03-02 16:30
405 查看
枚举每个文章里已经在Trie中被标记为可能是分割处的字符,然后再从此处跑Trie,继续向后标记。由于单词数很少,因此复杂度可以接受,O(n*m*Len)。
#include<cstdio> #include<cstring> using namespace std; int n,m,L; char s[1024*1024+100]; int ch[21*11][26]; bool is[21*11],end[1024*1024+100]; int sz; void Insert(char s[]) { int U=0,len=strlen(s); for(int i=0;i<len;++i) { int V=s[i]-'a'; if(!ch[U][V]) ch[U][V]=++sz; U=ch[U][V]; } is[U]=1; } void work(int x) { int i=x,j=ch[0][s[x]-'a']; while(i<L&&j) { if(is[j]) end[i]=1; ++i; j=ch[j][s[i]-'a']; } } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) {scanf("%s",s); Insert(s);} for(;m;--m) { scanf("%s",s); L=strlen(s); memset(end,0,L*sizeof(bool)); work(0); for(int i=0;i<L-1;++i) if(end[i]) work(i+1); for(int i=L-1;i>=0;--i) if(end[i]) {printf("%d\n",i+1); goto OUT;} puts("0"); OUT:; } return 0; }
相关文章推荐
- [bzoj1212] [HNOI2004]L语言(trie+dp)
- bzoj1212: [HNOI2004]L语言 Trie+dp
- [省选前题目整理][BZOJ 1212][HNOI 2004]L语言(Trie)
- 【BZOJ】1212 [HNOI2004]L语言 Trie
- [HNOI2004][bzoj1212] L语言 [Trie+dp]
- 【Trie+DP】BZOJ1212-[HNOI2004]L语言
- 【BZOJ1212】[HNOI2004]L语言【Trie】【暴力】
- bzoj1212 [HNOI2004]L语言(Trie+暴力)
- BZOJ 1212: [HNOI2004]L语言( dp + trie )
- [BZOJ1212]-[HNOI2004]L语言-trie+DP
- [bzoj1212][HNOI2004]L语言_AC自动机_动态规划
- BZOJ1212: [HNOI2004]L语言 AC自动机
- bzoj1212: [HNOI2004]L语言
- bzoj1212 [HNOI2004]L语言(AC+dp)
- bzoj 1212: [HNOI2004]L语言
- bzoj 1212: [HNOI2004]L语言(AC自动机+DP)
- BZOJ 1212: [HNOI2004]L语言
- BZOJ 1212 HNOI2004 L语言 AC自动机(Trie树)+动态规划
- bzoj 1212: [HNOI2004]L语言 AC自动机+状压
- BZOJ 1212 HNOI2004 L语言 AC自己主动机(Trie树)+动态规划