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. H5小游戏——看你有多色

    使用了封装了canvas的create.js库来实现的. 最终效果: 工程: Rect.js /* * 方块类 */ function Rect(n,color,specialColor){ crea ...

  2. div遮罩实现禁用鼠标(click、hover等)事件

    这两天在帮老师做网页,今天想实现在一块区域内禁止鼠标的各种事件,本来是想在框架模板的js文件里去修改,但是改代码的时候有点凌乱...感觉应该自己把问题想复杂了. 所以想了想要是能实现在一个区域内(如: ...

  3. js_网页导出pdf文件

    打印当前页面,一开始我认为是需要输出pdf的,后来了解的需求是能够打印就可以了.需求既然都研究了,记录下. 更好的打印方式,window.print();会弹出打印对话框,打印的是window.doc ...

  4. tf.segment_sum和tf.unsorted_segment_sum理解实例

    本文来自 guotong1988 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/guotong1988/article/details/77622790 import ...

  5. oracle查看表中数据的大小

    通过从视图 user_segments的字段 bytes中找到 select SUM(bytes)/1024/1024 from user_segments where segment_name='E ...

  6. Linux下如何打开img镜像文件

    有些镜像文件为IMG格式,在Linux如何打开呢?例如从微软dreampark下载的Windows Server 2008 R2镜像文件,使用file命令查看: $ file chs_windows_ ...

  7. Spring中的@Transactional事务注解

    事务注解方式 @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: @Transactional public class TestServiceBean impl ...

  8. [ python ] 字符串的操作及作业题

    字符串的操作方法 capitalize() : 首字母大写 s1 = 'my heart will go on' print(s1.capitalize()) # 首字母大写 # 执行结果: # My ...

  9. MySQL-IN和Exists区别

    1.in和exists in是把外表和内表作hash连接,而exists是对外表作loop循环,每次loop循环再对内表进行查询.一直以来认为exists比in效率高的说法是不准确的.  exists ...

  10. Learning a Deep Compact Image Representation for Visual Tracking

    这篇博客对论文进行了部分翻译http://blog.csdn.net/vintage_1/article/details/19546953,不过个人觉得博主有些理解有误. 这篇博客简单分析了代码htt ...