[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的进阶版本,主题思想差不多 ...
随机推荐
- 【不能继续浪啦】BZ做题记录[7.01~7.06]
距离上次提交..><居然已经过去一个半月了... 然后再去看看人家RXDoi.. 差距越来越大啦... 最后更新时间:7.06 19:06 [07.03 21:02]夏令营自修课逃逃真爽. ...
- 【BZOJ】2631: tree LCT
[题意]给定n个点的树,每个点初始权值为1,m次操作:1.x到y的点加值,2.断一条边并连一条边,保证仍是树,3.x到y的点乘值,4.x到y的点权值和取模.n,m<=10^5. [算法]Link ...
- 搭建自己的PHP框架心得——转载
原文:http://www.cnblogs.com/zhenbianshu/p/5331165.html 前言 说到写PHP的MVC框架,大家想到的第一个词--“造轮子”,是的,一个还没有深厚功力的程 ...
- 64_q1
QMsgBox-0-9.20130830git94677dc.fc26.i686.rpm 13-Feb-2017 23:40 40674 QMsgBox-0-9.20130830git94677dc. ...
- python使用unittest模块selenium访问斗鱼获取直播信息
import unittest from selenium import webdriver from bs4 import BeautifulSoup as bs class douyu(unitt ...
- SPOJ JZPLIT
Problem SPOJ Solution 考虑任意一个作为矩阵四个角的位置 \(r_i \oplus c_j\oplus a_{i,j}\oplus x_{i,j}=0\) \(r_i \oplus ...
- Mysql 中 char 、varchar 、text的区别
首先它们的存储方式和数据的检索方式都不一样.数据的检索效率是:char > varchar > text 空间占用方面,就要具体情况具体分析了. char:存储定长数据很方便,CHAR字段 ...
- selenium grid应用2-多节点执行用例
启动远程 node我们目前启动的 Hub 与 node 都是在一台主机.那么要在其它主机启动 node 必须满足以下几个要求: 1)本地 hub 主机与远程 node 主机之间可以相互 ping 通 ...
- [SVN技巧]代码提交中遇到的两个问题及其解决方案
前言 SVN在使用的过程中会遇到各种各样的问题,小黑在最近的使用中,遇到如下的两个问题,这里贴出来供大家参考 问题记录 SVN在源码仓库中不存在,导致无法删除和上传 问题提示: Working cop ...
- Windows内核读书笔记——Windows异常分发处理机制
本篇读书笔记主要参考自<深入解析Windows操作系统>和<软件调试>这两本书. IDT是处理异常,实现操作系统与CPU的交互的关口. 系统在初始化阶段会去填写这个结构. ID ...