la 3942 Rember_前缀树
#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_前缀树的更多相关文章
- [LA 3942] Remember the Word
Link: LA 3942 传送门 Solution: 感觉自己字符串不太行啊,要加练一些蓝书上的水题了…… $Trie$+$dp$ 转移方程:$dp[i]=sum\{ dp[i+len(x)+1]\ ...
- Trie(前缀树/字典树)及其应用
Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,PATRICIA tree,以及bitwise版本的crit-bit tree.当然很多名字的意义其实有交 ...
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- 【Todo】字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树
另开一文分析字符串相关的各种算法,以及用到的各种数据结构,包括前缀树后缀树等各种树. 先来一个汇总, 算法: 本文中提到的字符串匹配算法有:KMP, BM, Horspool, Sunday, BF, ...
- trie树(前缀树)
问题描述: Trie树,即字典树,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优 ...
- 【暑假】[实用数据结构]前缀树 Trie
前缀树Trie Trie可理解为一个能够快速插入与查询的集合,无论是插入还是查询所需时间都为O(m) 模板如下: +; ; struct Trie{ int ch[maxnode][sigma_siz ...
- [Swift]LeetCode208. 实现 Trie (前缀树) | Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie. ...
- 1042.D Petya and Array 前缀 + 树状数组
11.19.2018 1042.D Petya and ArrayNew Point: 前缀 + 树状数组 :树状数组逐个维护前缀个数 Describe: 给你一个数组,一个标记数,问你有多少区间[l ...
随机推荐
- UESTC_棋盘游戏 CDOJ 578
最近昀昀学习到了一种新的棋盘游戏,这是一个在一个N×N的格子棋盘上去搞M个棋子的游戏,游戏的规则有下列几条: 棋盘上有且仅有一个出口 开始时没有哪个棋子在出口,而且所有棋子都不相邻(这里的相邻是指上下 ...
- IOS添加多个按钮在导航栏
UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 75.0f, 30.0f)]; UIButton * ...
- Android自定义带标题边框的Layout
今天工作中又碰到个小问题,项目需要用到像Java Swing的JPanel一样带标题边框的布局,Android里没有类似控件,想到这个也不难,自己画了一个,是继承LinearLayout的一个自定义布 ...
- RMAN-format变量及configuration配置项
一.FORMAT字符串替代变量使用FORMAT参数时可使用的各种替换变量,如下:%c:备份片的拷贝数(从1开始编号):%d:数据库名称:%D:位于该月中的天数 (DD):%M:位于该年中的月份 (MM ...
- 【取对数+科学计数法】【HDU1060】 N^N
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- NET基础课--组件2
强命名组件:使用sn.exe生成公钥私钥对,公钥可以用工具查看.snk文件需严格保护. sn -k d:\iron.snk 生成公钥私钥对 sn -p d:\iron.snk d:\ ...
- Jquery时间段选择器
效果(有给小bug, 在时间的大小比较上.): HTML: <html> <head> <title>测试DatePicker</title> < ...
- C#中“@”的作用和用法
“@”在看别人程序的时候偶尔看到,总结了一下两个用途 1. 不常用,也不推介用的用法. @关键字 可以作为标识符来使用,说白了,就是讲关键字变成非关键字. 2.逐字字符串字面量,以@开头,后面是由引导 ...
- C# winform平台下使用spread控件导出excel表格
//首先要引入两个控件:1.根据自己的office 版本在项目->添加引用->microsoft office object 12.0 library (2010版) //2.在.net中 ...
- C#实现WinForm传值实例解析
C#实现WinForm传值的问题经常会做为公司面试的题目,那么作为学习C#以及WinForm传值,我们需要掌握哪些方法和思路呢?下面我们就向你介绍详细的思路和实现的具体步骤,希望对你有所帮助. C#实 ...