#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 400010
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int ch[N][30];
int val[N];
int cnt;
char str[N];
int d[N];
int idx(int c){
return c-'a';
}
void insert(char *s){
int i,n=strlen(s);
int c,u=0;
for(i=0;i<n;i++){
c=idx(s[i]);
if(!ch[u][c]){
memset(ch[cnt],0,sizeof(ch[cnt]));
val[cnt]=0;
ch[u][c]=cnt++;
}
u=ch[u][c];
}
val[u]=n;
}
void search(char *s,int i,int len){
int j;
int c,u=0;
for(j=0;j<len;j++){
c=idx(s[j]);
if(!ch[u][c])
break;
u=ch[u][c];
if(val[u])
d[i]=(d[i]+d[i+val[u]])%20071027;
}
}
int main(int argc, char** argv) {
int num=1;
int n,i,k;
char s[N];
while(scanf("%s",str)!=EOF){
cnt=1;
val[0]=0;
memset(ch[0],0,sizeof(ch[0]));
n=strlen(str);
scanf("%d",&k);
while(k--){
scanf("%s",s);
insert(s);
}
memset(d,0,sizeof(d));
d[n]=1;
for(i=n-1;i>=0;i--)
search(str+i,i,n-i);
printf("Case %d: %d\n",num++,d[0]);
}
return 0;
}

la 3942 Rember_前缀树的更多相关文章

  1. [LA 3942] Remember the Word

    Link: LA 3942 传送门 Solution: 感觉自己字符串不太行啊,要加练一些蓝书上的水题了…… $Trie$+$dp$ 转移方程:$dp[i]=sum\{ dp[i+len(x)+1]\ ...

  2. Trie(前缀树/字典树)及其应用

    Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...

  3. HDU1671——前缀树的一点感触

    题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...

  4. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  5. 【Todo】字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树

    另开一文分析字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树. 先来一个汇总, 算法: 本文中提到的字符串匹配算法有:KMP, BM, Horspool, Sunday, BF, ...

  6. trie树(前缀树)

    问题描述:   Trie树,即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优 ...

  7. 【暑假】[实用数据结构]前缀树 Trie

    前缀树Trie Trie可理解为一个能够快速插入与查询的集合,无论是插入还是查询所需时间都为O(m) 模板如下: +; ; struct Trie{ int ch[maxnode][sigma_siz ...

  8. [Swift]LeetCode208. 实现 Trie (前缀树) | Implement Trie (Prefix Tree)

    Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie. ...

  9. 1042.D Petya and Array 前缀 + 树状数组

    11.19.2018 1042.D Petya and ArrayNew Point: 前缀 + 树状数组 :树状数组逐个维护前缀个数 Describe: 给你一个数组,一个标记数,问你有多少区间[l ...

随机推荐

  1. http://bassistance.de/jquery-plugins/

    http://bassistance.de/jquery-plugins/ Query插件:手风琴 jQuery插件:自动完成 jQuery插件:留言 jQuery插件:密码验证 jQuery插件:P ...

  2. UESTC_How many good substrings CDOJ 1026

    Icerain likes strings very much. Especially the strings only consist of 0 and 1,she call them easy s ...

  3. Dos命令---ipconfig

    Dos命令---ipconfig 作者:vpoet mail:vpoet_sir@163.com ipconfig是很常用的Dos命令,我们可以用ipconfig /?查看该命令的说明.在linux下 ...

  4. ubuntu下的Samba配置:使每个用户可以用自己的用户名和密码登录自己的home目录

    http://blog.csdn.net/fly_qj/article/details/21744797 1.先要安装Samba sudo apt-get install samba openssh- ...

  5. SDP简要解析

    1.概述SDP也是MMUSIC工作组的一个产品,在MBONE内容中用得很多.其目的就是在媒体会话中,传递媒体流信息,允许会话描述的接收者去参与会话.SDP基本上在internet上工作.他定义了会话画 ...

  6. vue+webpack项目实战

    概述 -- 项目中会用到的插件 vue-router vue-resource 打包工具 webpack 依赖环境 node.js start 安装vue开发的模板 # 全局安装 vue-cli $ ...

  7. 第四章 Linux环境

    程序参数 main函数声明: int main(int  argc, char  *argv[]) 其中argc是接受到的参数个数,argv是存储参数的字符串数组. 或者声明为: main() 这样也 ...

  8. TCP协议三次握手

    TCP协议三次握手过程分析 TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: ...

  9. 为 IIS 7.0 配置 <system.webServer>

    Web.config 文件中的 system.webServer 节用于指定适用于 Web 应用程序的 IIS 7.0 设置.system.WebServer 是 configuration 节的子级 ...

  10. C盘扩容,超详细,史上最简单的扩容技术贴!

    http://ideapad.zol.com.cn/55/160_549015.html 很多朋友跟我一样,转到windows 7 64bit后,发现以前所谓的35GB理论不够用了,哪怕你不把任何程序 ...