POJ 1625 Censored!(大数+DP)
这题,真心木啥意思,就是数据里貌似字符有负数,注意gets读入。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstdlib>
using namespace std;
int trie[][];
int dp[][][];
int o[];
int que[];
int fail[];
int id[];
int t,N;
void CL()
{
t = ;
memset(trie,-,sizeof(trie));
memset(dp,,sizeof(dp));
memset(o,,sizeof(o));
memset(id,,sizeof(id));
}
void insert(char *str)
{
int len,i,root;
len = strlen(str);
root = ;
for(i = ;i < len;i ++)
{
if(trie[root][id[str[i]+]] == -)
trie[root][id[str[i]+]] = t ++;
root = trie[root][id[str[i]+]];
}
o[root] = ;
}
void build_ac()
{
int front,tail,head,i;
head = tail = ;
for(i = ;i < N;i ++)
{
if(trie[][i] != -)
{
fail[trie[][i]] = ;
que[tail++] = trie[][i];
}
else
{
trie[][i] = ;
}
}
while(head != tail)
{
front = que[head++];
if(o[fail[front]])
o[front] = ;
for(i = ;i < N;i ++)
{
if(trie[front][i] != -)
{
que[tail++] = trie[front][i];
fail[trie[front][i]] = trie[fail[front]][i];
}
else
{
trie[front][i] = trie[fail[front]][i];
}
}
}
}
int main()
{
int M,P,i,j,k,u;
int ans[];
char ch[];
while(scanf("%d%d%d%*c",&N,&M,&P)!=EOF)
{
CL();
gets(ch);
for(i = ;i < N;i ++)
{
id[ch[i]+] = i;
}
for(i = ;i < P;i ++)
{
gets(ch);
insert(ch);
}
build_ac();
dp[][][] = ;
for(i = ;i < M;i ++)
{
for(j = ;j < t;j ++)
{
if(o[j]) continue;
for(k = ;k < N;k ++)
{
if(o[trie[j][k]]) continue;
for(u = ;u < ;u ++)
{
dp[i+][trie[j][k]][u] += dp[i][j][u];
}
for(u = ;u < ;u ++)
{
if(dp[i+][trie[j][k]][u] > )
{
dp[i+][trie[j][k]][u+] += dp[i+][trie[j][k]][u]/;
dp[i+][trie[j][k]][u] = dp[i+][trie[j][k]][u]%;
}
}
}
}
}
memset(ans,,sizeof(ans));
for(i = ;i < t;i ++)
{
for(u = ;u < ;u ++)
{
ans[u] += dp[M][i][u];
}
for(u = ;u < ;u ++)
{
if(ans[u] > )
{
ans[u+] += ans[u]/;
ans[u] = ans[u]%;
}
}
}
int flag = ;
for(i = ;i >= ;i --)
{
if(ans[i] > )
flag = ;
if(flag)
printf("%d",ans[i]);
}
if(flag == )
printf("0\n");
else
printf("\n");
}
return ;
}
POJ 1625 Censored!(大数+DP)的更多相关文章
- POJ 1625 Censored!(AC自动机->指针版+DP+大数)题解
题目:给你n个字母,p个模式串,要你写一个长度为m的串,要求这个串不能包含模式串,问你这样的串最多能写几个 思路:dp+AC自动机应该能看出来,万万没想到这题还要加大数...orz 状态转移方程dp[ ...
- POJ 1625 Censored!(AC自动机 + DP + 大数 + 拓展ASCII处理)题解
题意:给出n个字符,p个病毒串,要你求出长度为m的不包含病毒串的主串的个数 思路:不给取模最恶劣情况$50^{50}$,所以用高精度板子.因为m比较小,可以直接用DP写. 因为给你的串的字符包含拓展A ...
- POJ 1625 Censored!(AC自动机+DP+高精度)
Censored! Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 6956 Accepted: 1887 Descrip ...
- POJ 1625 Censored!(AC自动机+高精度+dp)
http://poj.org/problem?id=1625 题意: 给出一些单词,求长度为m的串不包含这些单词的个数. 思路: 这道题和HDU 2243和POJ 2778是一样的,不同的是这道题不取 ...
- POJ 1625 Censored! (AC自己主动机 + 高精度 + DP)
题目链接:Censored! 解析:AC自己主动机 + 高精度 + 简单DP. 字符有可能会超过128.用map映射一下就可以. 中间的数太大.得上高精度. 用矩阵高速幂会超时,简单的DP就能解决时间 ...
- POJ 1625 Censored ( Trie图 && DP && 高精度 )
题意 : 给出 n 个单词组成的字符集 以及 p 个非法串,问你用字符集里面的单词构造长度为 m 的单词的方案数有多少种? 分析 :先构造出 Trie 图方便进行状态转移,这与在 POJ 2278 中 ...
- POJ 1625 Censored! [AC自动机 高精度]
Censored! Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 9793 Accepted: 2686 Descrip ...
- POJ 1625 Censored!
辣鸡OI毁我青春 Description The alphabet of Freeland consists of exactly N letters. Each sentence of Freela ...
- POJ.3624 Charm Bracelet(DP 01背包)
POJ.3624 Charm Bracelet(DP 01背包) 题意分析 裸01背包 代码总览 #include <iostream> #include <cstdio> # ...
随机推荐
- qsort用法总结
一.对int类型数组排序 ]; int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } qsort(nu ...
- [转]Spring的IOC原理[通俗解释一下]
1. IoC理论的背景我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 图1:软件系统中耦合的对象 如果我们打开机械 ...
- microsoft office安装选择
office分为零售版和批量授权版 零售版(文件名以cn开头)需要提供序列号才可以安装,而批量授权版(文件名以SW开头)可以先安装试用一段时间.
- Linux运维
概要:http://os.51cto.com/art/201312/423616.htm 论坛: http://www.linux360.cn/ https://www.centos.bz/ http ...
- 【转】ByteArrayOutputStream和ByteArrayInputStream详解
ByteArrayOutputStream类是在创建它的实例时,程序内部创建一个byte型别数组的缓冲区,然后利用ByteArrayOutputStream和ByteArrayInputStream的 ...
- 在64位的linux上运行32位的程序
1.症状 (1)执行bin文件时提示:No such file or directory (2)ldd bin文件 的输出为: not a dynamic executable (3)file bi ...
- codeforces A. Vasily the Bear and Triangle 解题报告
题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...
- GPU基本概念详解
§1 个 multiprocessor <-> 1个instruction unit <-> 8 个processor <-> 在一个warp中执行 < ...
- .net学习笔记---HttpRuntime类
HttpRuntime在ASP.NET处理请求中负责的是创建HttpContext对象以及调用HttpApplicationFactory创建HttpApplication. 其定义如下: publi ...
- MySQL Auto_Increment属性应用
我们经常要用到唯一编号,以标识记录.在MySQL中可通过数据列的AUTO_INCREMENT属性来自动生成.MySQL支持多种数据表,每种数据表的自增属性都有差异,这里将介绍各种数据表里的数据 ...