[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的进阶版本,主题思想差不多 ...
随机推荐
- jQuery domready
在jQuery里面,我们可以看到两种写法: $(function(){ //todo }) $(document).ready(function(){ //todo }) 这两个方法的效果都是一样的, ...
- three.js轨道控制器OrbitControls.js
https://blog.csdn.net/qq_37338983/article/details/78575333 文章地址
- Sqlmap注入技巧收集整理
TIP1 当我们注射的时候,判断注入 http://site/script?id=10http://site/script?id=11-1 # 相当于 id=10http://site/script? ...
- jsoup抓取网页报错UnsupportedMimeTypeException
今天在用Jsoup爬虫的时候两次遇到下面错误 Exception in thread "main" org.jsoup.UnsupportedMimeTypeException: ...
- windows安装linux虚拟机、修改apt源
记录一下windows安装虚拟机以及初始配置的一些坑. 安装VMware Workstation 直接百度搜索VMware,选择合适的版本下载: 按照一般软件的安装步骤安装VMware Worksta ...
- springMVC中ajax的实现
function addDebtResult(){ var repayIds=$("#repayIds").val(); var lateFeeDay=$("#repay ...
- html的loadrunner脚本
Action(){ char strs[20]; lr_start_transaction("api_sync_order"); web_add_header("SO ...
- Linux下var目录介绍
var目录 /var 包括系统运行时要改变的数据.其中包括每个系统是特定的,即不能够与其他计算机共享的目录,如/var/log,/var/lock,/var/run.有些目录还是可以与其他系统共享,如 ...
- AGC 16 D - XOR Replace
AGC 16 D - XOR Replace 附上attack(自为风月马前卒爷) 的题解 Problem Statement There is a sequence of length N: a=( ...
- 【转载】python import和from import
import和from import都是将其他模块导入当前模块中. 刚开始一直以为import和from import唯一的区别,就是from import可以少写一些模块名.虽然from XX im ...