枚举每个文章里已经在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;
}

最新文章

  1. reset 单个文件 回退
  2. Python之路【第十六篇续】Django进阶篇
  3. vector 之删除元素
  4. 转:Android Webview 加载外部html时选择加载本地的js,css等资源文件
  5. [Sciter系列] MFC下的Sciter&ndash;1.创建工程框架
  6. 潜语义分析(Latent Semantic Analysis)
  7. 跳转UICollectionViewController报Could not load NIB in bundle解决办法
  8. 值得赞扬的尝试与进步——CSDN开源夏令营第一印象
  9. PHP正则匹配与文件编码关系
  10. 在SpringBoot中使用FluentValidator验证插件
  11. 转载-Mac下iterm无法使用rz并提示waiting to receive.**B0100000023be50
  12. go http
  13. 影响solr性能的一些因素(附使用经验)
  14. 配置开发环境2——eclipse配置
  15. 挺不错的Java自学网站
  16. Swoole 结合TP5创建http服务
  17. [BZOJ2738]矩阵乘法(整体二分+二维树状数组)
  18. 《FPGA设计技巧与案例开发详解-第二版》全套资料包
  19. C# Message类的属性Msg所关联的消息ID
  20. Spring Boot 学习(一) 快速搭建SpringBoot 项目

热门文章

  1. POJ2236:Wireless Network(并查集)
  2. js中Date()对象详解
  3. Python 入门学习笔记
  4. 动态规划:LCIS
  5. Spring - IoC(7): 延迟实例化
  6. html5 游戏开发
  7. 【洛谷 P1896】[SCOI2005]互不侵犯(状压dp)
  8. Linux 开机自动挂载windows分区
  9. http://www.himigame.com/mac-cocoa-application/893.html
  10. 【乱入】Uva11021麻球繁衍