HDU 2825 Wireless Password(AC自动机+DP)
做题,
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define MOD 20090717
int trie[][];
int o[];
int fail[];
int que[];
int dp[][][];
int flag[];
int t;
void CL()
{
memset(trie,-,sizeof(trie));
memset(dp,,sizeof(dp));
memset(o,,sizeof(o));
t = ;
}
void insert(char *s,int num)
{
int root,i,len;
len = strlen(s);
root = ;
for(i = ;i < len;i ++)
{
if(trie[root][s[i]-'a'] == -)
trie[root][s[i]-'a'] = t ++;
root = trie[root][s[i]-'a'];
}
o[root] |= <<num;
}
void build_ac()
{
int head,tail,front,i;
head = tail = ;
for(i = ;i < ;i ++)
{
if(trie[][i] != -)
{
fail[trie[][i]] = ;
que[tail++] = trie[][i];
}
else
{
trie[][i] = ;
}
}
while(head != tail)
{
front = que[head++];
o[front] |= o[fail[front]];
for(i = ;i < ;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 n,m,r,k,i,j,u,x,y;
char str[];
for(i = ;i < ;i ++)
{
for(j = ;j < ;j ++)
{
if(i&(<<j)) flag[i] ++;
}
}
while(scanf("%d%d%d",&n,&m,&r)!=EOF)
{
if(n == &&m == &&r == ) break;
CL();
for(i = ;i < m;i ++)
{
scanf("%s",str);
insert(str,i);
}
build_ac();
dp[][][] = ;
x = ;y = ;
for(i = ;i < n;i ++)
{
memset(dp[y],,sizeof(dp[y]));
for(j = ;j < t;j ++)
{
for(k = ;k < (<<m);k ++)
{
if(dp[x][j][k] == ) continue;
for(u = ;u < ;u ++)
{
int temp = trie[j][u];
dp[y][temp][k|o[temp]] += dp[x][j][k];
if(dp[y][temp][k|o[temp]] >= MOD)
dp[y][temp][k|o[temp]] -= MOD;
}
}
}
swap(x,y);
}
int ans = ;
for(i = ;i < t;i ++)
{
for(j = ;j < (<<m);j ++)
{
if(flag[j] >= r)
ans = (ans + dp[x][i][j])%MOD;
}
}
printf("%d\n",ans);
}
return ;
}
找找手感。
HDU 2825 Wireless Password(AC自动机+DP)的更多相关文章
- HDU 2825 Wireless Password (AC自己主动机,DP)
pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...
- hdu 2825 Wireless Password(ac自己主动机&dp)
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU - 2825 Wireless Password(AC自己主动机+DP)
Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...
- hdu 4117 GRE Words AC自动机DP
题目:给出n个串,问最多能够选出多少个串,使得前面串是后面串的子串(按照输入顺序) 分析: 其实这题是这题SPOJ 7758. Growing Strings AC自动机DP的进阶版本,主题思想差不多 ...
- HDU 2825 Wireless Password【AC自动机+DP】
给m个单词,由这m个单词组成的一个新单词(两个单词可以重叠包含)长度为n,且新单词中包含的基本单词数目不少于k个.问这样的新单词共有多少个? m很小,用二进制表示新单词中包含基本单词的情况. 用m个单 ...
- 【HDU2825】Wireless Password (AC自动机+状压DP)
Wireless Password Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u De ...
- HDU2825 Wireless Password —— AC自动机 + 状压DP
题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others) ...
- HDU - 2825 Wireless Password (AC自动机+状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2825 题意:给一些字符串,构造出长度为n的字符串,它至少包含k个所给字符串,求能构造出的个数. 题解: ...
- HDU 2825 Wireless Password(AC自动机 + 状压DP)题解
题意:m个密码串,问你长度为n的至少含有k个不同密码串的密码有几个 思路:状压一下,在build的时候处理fail的时候要用 | 把所有的后缀都加上. 代码: #include<cmath> ...
随机推荐
- Delphi的属性Property
参考:http://www.cnblogs.com/edisonfeng/archive/2012/05/22/2513727.html 一.基本属性 TOnUserInfoShow = proced ...
- hdu 4049 2011北京赛区网络赛J 状压dp ***
cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...
- How to install the zsh shell in Linux && how to set it as a default login shell
Z shell’s (zsh) popularity has increased in the last years. I have not moved too zsh yet, but I am g ...
- 配置ogg异构oracle-mysql(2)源端配置
源端配置大致分为如下三个步骤:配置mgr,配置抽取进程,配置投递进程 在源端先创建一张表,记得带主键: SQL> create table ah4(id int ,name varchar(10 ...
- silverlight和wpf中暴露 给子类override
protected virtual void OnSelectionChanged(SelectionChangedEventArgs args) { } public TestTabControl( ...
- Codeforces VK Cup 2012 Round 3 A. Variable, or There and Back Again(dfs)
题目链接:http://codeforces.com/problemset/problem/164/A 思路:用vector分别保留原图和发图,然后分别从val值为1的点正向遍历,va值为2的点反向遍 ...
- python学习第二天
dict字典 把数据放入dict:直接赋值.初始化时指定 pop删除key set集合 add添加元素 remove删除元素 字符串str是不可变对象,对字符串的操作都会返回新的字符串 pass 什么 ...
- javascript概述
在我们进行javascript视频的时候,第一集,看到的学习要点: 1.什么是javascript? a.一种具有面向对象能力的.解释型的程序设计语言(直接读取运行,而非编译型) ...
- BNUOJ1067生成函数入门
https://www.bnuoj.com/v3/problem_show.php?pid=1067
- android MPAndroidChart饼图实现图例后加数字或文本(定制图例)
转载请注明:http://blog.csdn.net/ly20116/article/details/50905789 MPAndroidChart是一个非常优秀的开源图表库,MPAndroidCha ...