/*
开始想耍小聪明 直接map搞
代码短 好理解 空间够
恩 很好 就是 map慢死了
T了
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int n,m,ans;
string s,si;
map<string,int>t;
int main()
{
cin>>n;
while(n--)
{
map<string,int>f;
cin>>s;int l=s.length();
for(int i=;i<l;i++)
for(int j=i;j<l;j++)
{
si.clear();
for(int k=i;k<=j;k++)si=si+s[k];
if(!f[si])t[si]++,f[si]=;
}
}
cin>>m;
while(m--)
{
cin>>s;
cout<<t[s]<<endl;
}
return ;
}
/*
还是老老实实写字典树
这里不需要保证是前缀 只要有就可以
所以对于一个单词 我们把他所有的后缀加到字典树里
注意特殊的 abab这样的 如果按上面说的 会加两遍 ab
所以每个节点我们再维护一个last 表示这个小单词上次是在那个单词里出现
这样就ok了
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define maxn 1000010
using namespace std;
int n,m,topt;
char s[];
struct node
{
int next[],sum,last;
}t[maxn];
void Add_tree(int st,int p)
{
int now=,l=strlen(s);
for(int i=st;i<l;i++)
{
int x=s[i]-'a';
if(t[now].next[x])now=t[now].next[x];
else
{
topt++;t[now].next[x]=topt;now=topt;
}
if(t[now].last!=p)t[now].sum++;
t[now].last=p;
}
}
int find_tree()
{
int now=,p=,l=strlen(s);
while(p<=l-)
{
int x=s[p]-'a';
if(t[now].next[x])
{
p++;now=t[now].next[x];
}
else return ;
}
return t[now].sum;
}
int main()
{
scanf("%d",&n);
for(int k=;k<=n;k++)
{
scanf("%s",s);int l=strlen(s);
for(int i=;i<l;i++)
Add_tree(i,k);
}
scanf("%d",&m);
for(int k=;k<=m;k++)
{
scanf("%s",s);
printf("%d\n",find_tree());
}
return ;
}

HUD 2846 Repository的更多相关文章

  1. hdu 2846 Repository

    http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others)     ...

  2. HDU 2846 Repository (字典树 后缀建树)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  3. HDU 2846 Repository(字典树,每个子串建树,*s的使用)

    Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. poj 2846 Repository

    题目大意:给你n个字符串,然后给你m个子串,看这个子串在上面的多少个串中,出现过: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2846 本题可以在字 ...

  5. hdu 2846 Repository (字典树)

    RepositoryTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  6. HDU 2846 Repository(字典树,标记)

    题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...

  7. HDU 2846 Repository(字典树)

    字典树较为复杂的应用,我们在建立字典树的过程中需要把所有的前缀都加进去,还需要加一个id,判断它原先是属于哪个串的.有人说是AC自动机的简化,但是AC自动机我还没有做过. #include<io ...

  8. HDU:2846-Repository

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2846 Repository Time Limit: 2000/1000 MS (Java/Others) ...

  9. HDU 2846:Repository(Trie)

    http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...

随机推荐

  1. 优化HTTP前端请求构建高性能ASP.NET站点

    HTTP请求的优化  在一个网页的请求过程中,其实整个页面的html结构(就是页面的那些html骨架)请求的时间是很短的,一般是占整个页面的请求时间的10%-20%.在页面加载的其余的时间实际上就是在 ...

  2. ‘for’ loop initial declarations are only allowed in C99 mode

    #include <stdio.h>int main(){ for(int i=0;i<10;i++){ printf("\n%d",i); } return 0 ...

  3. eval函数:\的应用

    <?php $string = "beautiful"; $time = "winter"; $str = 'This is a $string $tim ...

  4. 转:PHP include()和require()方法的区别

    文章来自于:http://developer.51cto.com/art/200909/153687.htm 本文总结了PHP的include()和require()两种包含外部文件的方法的不同之处. ...

  5. 从MVC框架看MVC架构的设计(转)

    尽管MVC早已不是什么新鲜话题了,但是从近些年一些优秀MVC框架的设计上,我们还是会发现MVC在架构设计上的一些新亮点.本文将对传统MVC架构中的一些弊病进行解读,了解一些优秀MVC框架是如何化解这些 ...

  6. sphinx,github和readthedocs配合使用

    http://daler.github.io/sphinxdoc-test/includeme.html http://pages.github.com/ http://www.lulinfeng.c ...

  7. 【HDOJ】4986 Little Pony and Alohomora Part I

    递推.设n个盒子的Spell次数为S(n),期望为E(n).当有n个盒子时,可能第n把钥匙在第n个盒子中,此时的Spell次数应该为(n-1)!+S(n-1):当第n把钥匙不在第n个盒子中,混合排列, ...

  8. -_-#【Backbone】Router

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. 【宽搜】【并查集】Vijos P1015 十字绣

    题目链接: https://vijos.org/p/1015 题目大意: n*m的网格,线只能在网格的顶点处才能从布的一面穿到另一面.每一段线都覆盖一个单位网格的两条对角线之一,而在绣的过程中,一针中 ...

  10. DEV控件的使用(二次封装BaseUI)

    一:DEV的安装 直接点击exe文件安装,安装完成之后,将控件添加到工具栏,如下图添加即可 二:注意事项 项目使用的是二次封装的BaseUI,有些属性和事件在BaseUI的控件中由于太多不能全部显示, ...