POJ1625 Censored!
来源:互联网 发布:HTML5和php区别 编辑:程序博客网 时间:2024/06/10 16:56
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.
与bzoj1030文本生成器【传送门】几乎一样,需要写高精。
详细题解见如上链接。
#include<cstdio>#include<cstring>#include<queue>using namespace std;struct bigint{ int l,a[50]; bigint operator + (const bigint &b) const { int i,j,k,x,y; bigint ans; memset(ans.a,0,sizeof(ans.a)); for (i=1;i<=l||i<=b.l;i++) { ans.a[i]+=a[i]+b.a[i]; ans.a[i+1]=ans.a[i]/10000; ans.a[i]%=10000; } if (l>b.l) ans.l=l; else ans.l=b.l; if (ans.a[ans.l+1]) ans.l++; return ans; }}dp[60][3000],one,ans;void prt(bigint p){ int i,j,k,m,n,q,x,y,z; printf("%d",p.a[p.l]); for (i=p.l-1;i>=1;i--) { x=p.a[i]; if (x<1000) printf("0"); if (x<100) printf("0"); if (x<10) printf("0"); printf("%d",x); } printf("\n");}int ord[500],t[3000][60],f[3000],si;bool b[3000];int main(){ int i,j,k,l,m,n,p,q,x,y,z; unsigned char c,s[20]; one.a[1]=one.l=1; scanf("%d%d%d\n",&n,&m,&k); for (i=1;i<=n;i++) { scanf("%c",&c); ord[c]=i; } for (i=1;i<=k;i++) { scanf("%s",s+1); p=0; for (j=1;s[j]!='\0';j++) { if (!t[p][ord[s[j]]]) t[p][ord[s[j]]]=++si; p=t[p][ord[s[j]]]; } b[p]=1; } queue<int> que; for (i=1;i<=n;i++) if (t[0][i]) que.push(t[0][i]); while (!que.empty()) { x=que.front(); que.pop(); for (i=1;i<=n;i++) if (t[x][i]) { f[t[x][i]]=t[f[x]][i]; que.push(t[x][i]); if (b[f[t[x][i]]]) b[t[x][i]]=1; } else t[x][i]=t[f[x]][i]; } for (i=1;i<=n;i++) if (!b[t[0][i]]) dp[1][t[0][i]]=dp[1][t[0][i]]+one; for (i=1;i<m;i++) for (j=0;j<=si;j++) for (k=1;k<=n;k++) if (!b[t[j][k]]) dp[i+1][t[j][k]]=dp[i+1][t[j][k]]+dp[i][j]; for (i=0;i<=si;i++) ans=ans+dp[m][i]; prt(ans); }
- poj1625 Censored!
- POJ1625 Censored!
- POJ1625-Censored!
- [poj1625] 检查Censored!
- poj1625 Censored! AC自动机+DP
- POJ1625 Censored! AC自动机+DP+高精度
- poj1625 Censored! AC自动机DP、高精度
- poj1625 Censored! 高精度+ac机+dp
- POJ1625---Censored!(AC自动机+dp+高精度)
- POJ1625 Censored! AC自动机+dp+高精度
- poj1625
- poj1625
- POJ1625----AC自动机+大数+DP
- POJ1625--AC自动机+DP+大数
- AC自动机+DP+大数poj1625
- AC自动机+dp+大数 poj1625
- POJ1625-(AC自动机+DP+大数)
- poj 1625 Censored!
- linux上安装nginx
- 不使用中间变量交换两个数的值
- OpenGL---三维变换
- MySQL基于gtid特性与xtrabackup的数据恢复
- windows环境下如何安装memcached教程
- POJ1625 Censored!
- 如何修改Matlab默认启动目录?
- java的继承和多态
- POJ1321 棋盘问题
- Android getColor方法提示过时
- MySql简单入门一
- python字符操作函数总结
- 求一元二次方程的解:
- 读书笔记-现代操作系统-7多媒体操作系统-7.1多媒体简介7.2 多媒体文件