Censored!
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 9793   Accepted: 2686

Description

The alphabet of Freeland consists of exactly N letters. Each sentence of Freeland language (also known as Freish) consists of exactly M letters without word breaks. So, there exist exactly N^M different Freish sentences.

But after recent election of Mr. Grass Jr. as Freeland president some words offending him were declared unprintable and all sentences containing at least one of them were forbidden. The sentence S contains a word W if W is a substring of S i.e. exists such k >= 1 that S[k] = W[1], S[k+1] = W[2], ...,S[k+len(W)-1] = W[len(W)], where k+len(W)-1 <= M and len(W) denotes length of W. Everyone who uses a forbidden sentence is to be put to jail for 10 years.

Find out how many different sentences can be used now by freelanders without risk to be put to jail for using it.

Input

The first line of the input file contains three integer numbers: N -- the number of letters in Freish alphabet, M -- the length of all Freish sentences and P -- the number of forbidden words (1 <= N <= 50, 1 <= M <= 50, 0 <= P <= 10).

The second line contains exactly N different characters -- the letters of the Freish alphabet (all with ASCII code greater than 32).

The following P lines contain forbidden words, each not longer than min(M, 10) characters, all containing only letters of Freish alphabet.

Output

Output the only integer number -- the number of different sentences freelanders can safely use.

Sample Input

2 3 1
ab
bb

Sample Output

5

Source

Northeastern Europe 2001, Northern Subregion

题意:

给出p个模式串,求有多少个长度为m的字符串,其中不包含任何一个模式串为子串


和BZOJ1030一样啊
字符集未知,所以用个映射
可恶一开始映射写错了(雾?现在我还不知道为什么错 反正用mp[s[i]]=i就对了
然后不准取模还要用高精.....
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=,M=,L=,B=1e4;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,p,mp[];
char s[N];
struct node{
int ch[],fail,val;
}t[N];
int sz;
void ins(char s[]){
int u=,n=strlen(s+);
for(int i=;i<=n;i++){
int c=mp[s[i]];
if(!t[u].ch[c]) t[u].ch[c]=++sz;
u=t[u].ch[c];
}
t[u].val=;
}
int q[N],head,tail;
void getAC(){
head=tail=;
for(int i=;i<=mp[];i++) if(t[].ch[i]) q[tail++]=t[].ch[i];
while(head!=tail){
int u=q[head++];
t[u].val|=t[t[u].fail].val;
for(int i=;i<=mp[];i++){
int &v=t[u].ch[i];
if(!v) v=t[t[u].fail].ch[i];
else{
t[v].fail=t[t[u].fail].ch[i];
q[tail++]=v;
}
}
}
} struct big{
int size,d[L];
big():size(){memset(d,,sizeof(d));}
bool has(){return size>||(size==&&d[]!=);}
};
big operator +(big a,big b){
int g=,i;
for(i=;;i++){
if(g==&&i>a.size&&i>b.size) break;
int t=g;
t+=i<=a.size?a.d[i]:;
t+=i<=b.size?b.d[i]:;
a.d[i]=t%B;
g=t/B;
}
a.size=i-;
return a;
}
void print(big &a){
printf("%d",a.d[a.size]);
for(int i=a.size-;i>=;i--){
if(a.d[i]<) printf("");
else if(a.d[i]<) printf("");
else if(a.d[i]<) printf("");
printf("%d",a.d[i]);
}
putchar('\n');
} big f[M][N],ans;
void dp(){
f[][].d[]=;
for(int i=;i<m;i++)
for(int j=;j<=sz;j++) if(!t[j].val&&f[i][j].has())
for(int k=;k<=mp[];k++) if(!t[t[j].ch[k]].val)
f[i+][t[j].ch[k]]=f[i+][t[j].ch[k]]+f[i][j];
for(int i=;i<=sz;i++) ans=ans+f[m][i];
print(ans);
}
int main(){
freopen("in","r",stdin);
n=read();m=read();p=read();
scanf("%s",s+);
for(int i=;i<=n;i++) mp[s[i]]=i;mp[]=n;
for(int i=;i<=p;i++) scanf("%s",s+),ins(s);
//for(int i=1;i<=n;i++) printf("mp %c %d\n",s[i],mp[s[i]]);
getAC();
dp();
}
 

POJ 1625 Censored! [AC自动机 高精度]的更多相关文章

  1. POJ 1625 Censored!(AC自动机+DP+高精度)

    Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Descrip ...

  2. poj 1625 (AC自动机好模版,大数好模版)

    题目 给n个字母,构成长度为m的串,总共有n^m种.给p个字符串,问n^m种字符串中不包含(不是子串)这p个字符串的个数. 将p个不能包含的字符串建立AC自动机,每个结点用val值来标记以当前节点为后 ...

  3. Match:Censored!(AC自动机+DP+高精度)(POJ 1625)

     Censored! 题目大意:给定一些字符,将这些字符组成一个固定长度的字符串,但是字符串不能包含一些禁词,问你有多少种组合方式. 这是一道好题,既然出现了“一些”禁词,那么这题肯定和AC自动机有点 ...

  4. POJ 1625 Censored!(AC自动机->指针版+DP+大数)题解

    题目:给你n个字母,p个模式串,要你写一个长度为m的串,要求这个串不能包含模式串,问你这样的串最多能写几个 思路:dp+AC自动机应该能看出来,万万没想到这题还要加大数...orz 状态转移方程dp[ ...

  5. poj 2278 DNASequnce AC自动机

    地址:http://poj.org/problem?id=2778 题目: DNA Sequence Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  6. ZOJ 3494 (AC自动机+高精度数位DP)

    题目链接:  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3494 题目大意:给定一些被禁止的BCD码.问指定范围内不含有 ...

  7. POJ 1625 Censored!

    辣鸡OI毁我青春 Description The alphabet of Freeland consists of exactly N letters. Each sentence of Freela ...

  8. DNA Sequence - POJ 2778(AC自动机+矩阵乘法)

    题目大意:DNA序列是有 ATGC 组成的,现在知道一些动物的遗传片段有害的,那么如果给出这些有害的片段,能否求出来所有长度为 N 的基因中有多少是不包含这些有害片段的.   分析:也是断断续续做了一 ...

  9. POJ 1625 Censored!(AC自动机+高精度+dp)

    http://poj.org/problem?id=1625 题意: 给出一些单词,求长度为m的串不包含这些单词的个数. 思路: 这道题和HDU 2243和POJ 2778是一样的,不同的是这道题不取 ...

随机推荐

  1. TCP层的分段和IP层的分片之间的关系 & MTU和MSS之间的关系 (转载)

    首先说明:数据报的分段和分片确实发生,分段发生在传输层,分片发生在网络层.但是对于分段来说,这是经常发生在UDP传输层协议上的情况,对于传输层使用TCP协议的通道来说,这种事情很少发生. 1,MTU( ...

  2. javascript数据类型及转换

    此篇数据类型和转换只限于ECMA规范,规范用了比较大的篇幅讲数据类型和类型转换,理解了这个最基本的概念对表达式.语句.执行环境.对象及继承都有非常大的帮助,遂整理如下: 数据类型和值 类型转换 表达式 ...

  3. Sqoop导入导出的几个例子

    Sqoop导入导出的几个例子 http://sqoop.apache.org/docs/1.4.6/SqoopUserGuide.html#_importing_data_into_hive   no ...

  4. linux 下查看有当前文件夹有多少个文件

    ls |wc -w

  5. MapReduce 原理与 Python 实践

    MapReduce 原理与 Python 实践 1. MapReduce 原理 以下是个人在MongoDB和Redis实际应用中总结的Map-Reduce的理解 Hadoop 的 MapReduce ...

  6. eclipse出现错误:he type java.util.Map$Entry cannot be resolved. It is indirectly referenced

    eclipse出现错误:he type java.util.Map$Entry cannot be resolved. It is indirectly referenced jre 换成6的就好了选 ...

  7. 开地址哈希表(Hash Table)的接口定义与实现分析

    开地址哈希函数的接口定义 基本的操作包括:初始化开地址哈希表.销毁开地址哈希表.插入元素.删除元素.查找元素.获取元素个数. 各种操作的定义如下: ohtbl_init int ohtbl_init ...

  8. python_如何获取文件状态

    案例: 在某项目中,需要获取文件状态,如: 文件的类型(普通文件.目录.符合连接.设备文件) 文件的访问权限 文件最后 访问.修改.节点状态 时间 普通文件大小 -- 如何解决? 方法1:通过os原始 ...

  9. wstring操作与普通段字符操作对照表

    字符分类:   宽字符函数普通C函数描述   iswalnum()   isalnum()   测试字符是否为数字或字母   iswalpha()   isalpha()   测试字符是否是字母    ...

  10. MySQL如何选择合适的引擎以及引擎的转换。

    我们怎么选择合适的引擎?这里简单归纳一句话:"除非需要用到某些InnoDB不具备的特性,并且没有其他办法可以替代,否则都应该优先选择InnoDB引擎." 除非万不得已,否则不建议混 ...