Censored!
Time Limit: 5000MS   Memory Limit: 10000K
Total Submissions: 10824   Accepted: 2966

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

同HDU2222,只是需要高精度

感觉可能有个问题,就是这题题目没有规定屏蔽词包含了所有字母,但是好像对解题没有什么影响。

代码用时:1.5h 高精度输出写炸了

 #include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
using namespace std; const int N=;
int n,m,p,nd,fail[N],b[N],q[N],c[N][N];
char s[N],S[N]; int get(char ch){ rep(i,,n) if (S[i]==ch) return i; return -; } void ins(char S[]){
int x=,len=strlen(s+);
rep(i,,len){
int k=get(s[i]);
if (!c[x][k]) ++nd,c[x][k]=nd;
x=c[x][k];
}
b[x]=;
} void getfail(){
int st=,ed=;
rep(i,,n) if (c[][i]) q[++ed]=c[][i];
while (st!=ed){
int x=q[++st];
rep(i,,n)
if (!c[x][i]) c[x][i]=c[fail[x]][i];
else q[++ed]=c[x][i],fail[c[x][i]]=c[fail[x]][i];
b[x]|=b[fail[x]];
}
} struct D{
int v[N],len;
D(int x=){
memset(v,,sizeof(v));
for (len=; x>; x/=) v[len++]=x%;
len--;
}
D operator +(const D &a){
D ans;
ans.len=max(len,a.len);
for (int i=; i<=ans.len; i++){
ans.v[i]+=v[i]+a.v[i]; ans.v[i+]+=ans.v[i]/; ans.v[i]%=;
}
while (ans.v[ans.len+]) ans.len++;
return ans;
}
void print(){
if (len==-) { printf("%d\n",); return; }
for (int i=len; ~i; i--) printf("%d",v[i]);
printf("\n");
}
}dp[][N]; int check(int k,int j){ int ans=; rep(i,,n) if (c[k][i]==j) ans++; return ans; } int main(){
freopen("poj1625.in","r",stdin);
freopen("poj1625.out","w",stdout);
scanf("%d%d%d",&n,&m,&p); scanf("%s",S+);
rep(i,,p) scanf("%s",s+),ins(s);
getfail(); dp[][]=D();
rep(i,,m) rep(j,,nd) if (!b[j])
rep(k,,nd) if (!b[k])
for (int ti=check(k,j); ti--; ) dp[i][j]=dp[i][j]+dp[i-][k];
D ans; rep(i,,nd) ans=ans+dp[m][i];
ans.print();
return ;
}

[POJ1625]Censored!(AC自动机+DP+高精度)的更多相关文章

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

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

  2. POJ1625 Censored! —— AC自动机 + DP + 大数

    题目链接:https://vjudge.net/problem/POJ-1625 Censored! Time Limit: 5000MS   Memory Limit: 10000K Total S ...

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

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

  4. POJ1625 Censored!(AC自动机+DP)

    题目问长度m不包含一些不文明单词的字符串有多少个. 依然是水水的AC自动机+DP..做完后发现居然和POJ2778是一道题,回过头来看都水水的... dp[i][j]表示长度i(在自动机转移i步)且后 ...

  5. 对AC自动机+DP题的一些汇总与一丝总结 (2)

    POJ 2778 DNA Sequence (1)题意 : 给出m个病毒串,问你由ATGC构成的长度为 n 且不包含这些病毒串的个数有多少个 关键字眼:不包含,个数,长度 DP[i][j] : 表示长 ...

  6. Ural 1158. Censored! 有限状态自动机+DP+大整数

    Ural1158 看上去很困难的一道题. 原文地址 http://blog.csdn.net/prolightsfxjh/article/details/54729646 题意:给出n个不同的字符,用 ...

  7. HDU2296 Ring(AC自动机+DP)

    题目是给几个带有价值的单词.而一个字符串的价值是 各单词在它里面出现次数*单词价值 的和,问长度不超过n的最大价值的字符串是什么? 依然是入门的AC自动机+DP题..不一样的是这题要输出具体方案,加个 ...

  8. HDU2457 DNA repair(AC自动机+DP)

    题目一串DNA最少需要修改几个基因使其不包含一些致病DNA片段. 这道题应该是AC自动机+DP的入门题了,有POJ2778基础不难写出来. dp[i][j]表示原DNA前i位(在AC自动机上转移i步) ...

  9. hdu 4117 GRE Words AC自动机DP

    题目:给出n个串,问最多能够选出多少个串,使得前面串是后面串的子串(按照输入顺序) 分析: 其实这题是这题SPOJ 7758. Growing Strings AC自动机DP的进阶版本,主题思想差不多 ...

随机推荐

  1. CodeForces - 1004C

    Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...

  2. webpack编译报错:Module not found: Error: Cannot resolve 'file' or 'directory' ./../../node_modules..

    在同事的mac电脑上,可以正常编译,拿到我这边就出错了(⊙﹏⊙) 好像是webpack在window下的一个bug,需要让 webpack 和你的项目保持在一个盘符下,参考. 解决方法: 修改conf ...

  3. 千字短文解决工程师们关于SPI的迷糊!

    串行外设接口 (SPI) 总线是一个工作在全双工模式下的同步串行数据链路.它可用于在单个主控制器和一个或多个从设备之间交换数据.其简单的实施方案只使用四条支持数据与控制的信号线(图 1): 图1:基本 ...

  4. selenium启动chrome模拟器模拟手机

    一.如果chrome选项里边有这个模拟设备(比如iPhone 6 Plus): 1.先启动Selenium Grid, 比如命令:java -jar selenium-server-standalon ...

  5. PHP 利用nginx的X-sendfile控制下载,提高下载效率

    https://blog.csdn.net/qq_34839657/article/details/52812885 https://www.jianshu.com/p/bf5c387830b7 为了 ...

  6. 主机名/etc/hosts文件的作用

    1,/etc/hosts,主机名ip配置文件. # Do not remove the following line, or various programs # that require netwo ...

  7. csu 1769(数学)

    1769: 想打架吗?算我一个!所有人,都过来!(3) Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 262  Solved: 76[Submit][S ...

  8. Effective STL 笔记: Item 6--Be alert for C++'s most vexing parse

    假设有个文件里面记录的一系列的 int 值,现在我们想把这些数值存到一个 List 里面,结合 Item 5, 我们可能会写出下面的代码: ifstream dataFile("ints.d ...

  9. HEVC代码记录(删除)

    得到编码残差  TEncSearch.cpp 4543:rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );

  10. 洛谷P1008三连击 题解

    题目传送门 使用dfs搜索,搜索9个数字,注意回溯...最后判断是否符合条件,输出. #include<bits/stdc++.h> using namespace std; ],a[]; ...