[POJ1625]Censored!(AC自动机+DP+高精度)
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
bbSample Output
5Source
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+高精度)的更多相关文章
- POJ 1625 Censored!(AC自动机+DP+高精度)
Censored! Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 6956 Accepted: 1887 Descrip ...
- POJ1625 Censored! —— AC自动机 + DP + 大数
题目链接:https://vjudge.net/problem/POJ-1625 Censored! Time Limit: 5000MS Memory Limit: 10000K Total S ...
- Match:Censored!(AC自动机+DP+高精度)(POJ 1625)
Censored! 题目大意:给定一些字符,将这些字符组成一个固定长度的字符串,但是字符串不能包含一些禁词,问你有多少种组合方式. 这是一道好题,既然出现了“一些”禁词,那么这题肯定和AC自动机有点 ...
- POJ1625 Censored!(AC自动机+DP)
题目问长度m不包含一些不文明单词的字符串有多少个. 依然是水水的AC自动机+DP..做完后发现居然和POJ2778是一道题,回过头来看都水水的... dp[i][j]表示长度i(在自动机转移i步)且后 ...
- 对AC自动机+DP题的一些汇总与一丝总结 (2)
POJ 2778 DNA Sequence (1)题意 : 给出m个病毒串,问你由ATGC构成的长度为 n 且不包含这些病毒串的个数有多少个 关键字眼:不包含,个数,长度 DP[i][j] : 表示长 ...
- Ural 1158. Censored! 有限状态自动机+DP+大整数
Ural1158 看上去很困难的一道题. 原文地址 http://blog.csdn.net/prolightsfxjh/article/details/54729646 题意:给出n个不同的字符,用 ...
- HDU2296 Ring(AC自动机+DP)
题目是给几个带有价值的单词.而一个字符串的价值是 各单词在它里面出现次数*单词价值 的和,问长度不超过n的最大价值的字符串是什么? 依然是入门的AC自动机+DP题..不一样的是这题要输出具体方案,加个 ...
- HDU2457 DNA repair(AC自动机+DP)
题目一串DNA最少需要修改几个基因使其不包含一些致病DNA片段. 这道题应该是AC自动机+DP的入门题了,有POJ2778基础不难写出来. dp[i][j]表示原DNA前i位(在AC自动机上转移i步) ...
- hdu 4117 GRE Words AC自动机DP
题目:给出n个串,问最多能够选出多少个串,使得前面串是后面串的子串(按照输入顺序) 分析: 其实这题是这题SPOJ 7758. Growing Strings AC自动机DP的进阶版本,主题思想差不多 ...
随机推荐
- 关于Http协议、ASP.NET 核心知识(2)
简介HTTP (对于http协议的描述我前部分有写,但基于保证文档独立完整性的原则,我再写一遍.反正又不花钱.) 这货的学名叫:超文本传输协议 英文名字:(HTTP,HyperText Transfe ...
- CodeForces - 877C
Slava plays his favorite game "Peace Lightning". Now he is flying a bomber on a very speci ...
- 2016CCPC东北地区大学生程序设计竞赛 (2018年8月22日组队训练赛)
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016CCPC%B6%AB%B1%B1%B5%D8%C7%F8%B4%F3%D ...
- textarea输入框随内容撑开高度
原文链接 方法一(jquery): $('textarea').each(function () { this.setAttribute('style', 'height:' + (this.scr ...
- jquery对象和javascript对象即DOM对象相互转换
jquery对象和javascript对象即DOM对象相互转换 1. DOM 对象转成 jQuery 对象对于已经是一个 DOM 对象,只需要用 $() 把DOM对象包装起来,就可以获得一个 jQue ...
- python模块之itertools
在循环对象和函数对象中,我们了解了循环器(iterator)的功能.循环器是对象的容器,包含有多个对象.通过调用循环器的next()方法 (__next__()方法,在Python 3.x中),循环器 ...
- 使用jolokia api监控ActiveMQ
jolokia api提供了一种通过HTTP访问JMX获得AMQ后台数据的一种方式,即Restful Api #!/usr/bin/env python # -*- coding:utf-8 -*- ...
- HDU 1285 确定比赛名次(拓扑排序模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 题目大意:有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行 ...
- Gitlab部署及汉化操作
一.简介 GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github类似的功能 ...
- Single Image Haze Removal(图像去雾)-CVPR’09 Best Paper
公式推导 paper闪光点 找到了一个很简洁的假设. paper不足 代码跑起来很慢.据说2010年的ECCV那篇是改进的.