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 ...
随机推荐
- Linux系统编程(4)——文件与IO之ioctl函数
ioctl是设备驱动程序中对设备的I/O通道进行管理的函数.所谓对I/O通道进行管理,就是对设备的一些特性进行控制,例如串口的传输波特率.马达的转速等等.它的参数个数如下:int ioctl(int ...
- RabbitMQ中文入门教程
原文地址:http://adamlu.net/dev/2011/09/rabbitmq-get-started/ 这系列教程是翻译官方入门教程. 第一部分:Hello World第二部分:工作队列(W ...
- HDU 5775 Bubble Sort(线段树)(2016 Multi-University Training Contest 4 1012)
原址地址:http://ibupu.link/?id=31 Problem Description P is a permutation of the integers from 1 to N(ind ...
- hdu 5626 Clarke and points
Problem Description Clarke is a patient with multiple personality disorder. One day he turned into a ...
- MP3/WAV 播放
一.编译libmad 1.先下载压缩包到本地,并解压 tar -xvzf libmad-0.15.1b.tar.gz -C ./ 2.进入源代码文件夹并配置 编写一个配置文件,便于< ...
- 自定义视图控制器切换(iOS)
在iOS开发过程中,通常我们会使用UINavigationController,UITabbarController等苹果提供的视图控制器来切换我们的视图.在iOS5之前,如果要自定义容器视图控制器很 ...
- winform —— listview创建表及简单的增删改查
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- Jquery时间段选择器
效果(有给小bug, 在时间的大小比较上.): HTML: <html> <head> <title>测试DatePicker</title> < ...
- .NET Framework 4.0-RequestValidationMode
1.WebForm 先看如下 web.config 的代码: <system.web> <compilation debug="true" targetFrame ...
- 我的美国(北美)计算机CS实习面试经验分享
过去的一年多里,参加了一些面试,虽然面过的公司不多,但都从头一直走到尾.毕竟自己也是花了大量的时间和精力在这一场场的面试里.所以,就絮叨下自己的一些经验,希望能给在美国找实习找工作的同学们提供一点点帮 ...