题目链接

做题,

 #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)的更多相关文章

  1. HDU 2825 Wireless Password (AC自己主动机,DP)

    pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...

  2. hdu 2825 Wireless Password(ac自己主动机&amp;dp)

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. HDU - 2825 Wireless Password(AC自己主动机+DP)

    Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...

  4. hdu 4117 GRE Words AC自动机DP

    题目:给出n个串,问最多能够选出多少个串,使得前面串是后面串的子串(按照输入顺序) 分析: 其实这题是这题SPOJ 7758. Growing Strings AC自动机DP的进阶版本,主题思想差不多 ...

  5. HDU 2825 Wireless Password【AC自动机+DP】

    给m个单词,由这m个单词组成的一个新单词(两个单词可以重叠包含)长度为n,且新单词中包含的基本单词数目不少于k个.问这样的新单词共有多少个? m很小,用二进制表示新单词中包含基本单词的情况. 用m个单 ...

  6. 【HDU2825】Wireless Password (AC自动机+状压DP)

    Wireless Password Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u De ...

  7. HDU2825 Wireless Password —— AC自动机 + 状压DP

    题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others)    ...

  8. HDU - 2825 Wireless Password (AC自动机+状压DP)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2825 题意:给一些字符串,构造出长度为n的字符串,它至少包含k个所给字符串,求能构造出的个数. 题解: ...

  9. HDU 2825 Wireless Password(AC自动机 + 状压DP)题解

    题意:m个密码串,问你长度为n的至少含有k个不同密码串的密码有几个 思路:状压一下,在build的时候处理fail的时候要用 | 把所有的后缀都加上. 代码: #include<cmath> ...

随机推荐

  1. ListView 完全优化 + 多种listitem布局处理

    #  百度了下,感觉下面的博客文章还都挺全面的,写的很好,直接分享得了 Android性能优化--Listview优化 - tonycheng93 - 博客园http://www.cnblogs.co ...

  2. 【翻译五】java-中断机制

    Interrupts An interrupt is an indication to a thread that it should stop what it is doing and do som ...

  3. [LeetCode] Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  4. SQL Server创建随机测试数据

    我们在做数据仓库开发的过程中,经常需要插入大量的测试数据来测试数据库查询性能和计算占用的存储空间等.本文主要介绍下不借用第三方的工具在数据库中直接生成大量的测试数据. 需求 每一行包含5个日期字段和一 ...

  5. DTMF的原理分析

    转自:http://blog.csdn.net/wangwenwen/article/details/8264925 1. DTMF原理 DTMF(Double Tone MulitiFrequenc ...

  6. VMware报错:“device eth0 does not seem to be present, delaying initialization ”

    转自:http://blog.sina.com.cn/s/blog_77126fa501018s3d.html vmlite虚拟机启动出错,就把这个虚拟机删除掉重新建立,系统虚拟硬盘使用之前的,启动系 ...

  7. bbed的使用--查看数据文件信息 & sid信息

    1.得到文件的块大小和数据块个数 在Linux和Unix上,oracle提供了一个小工具dbfsize用于查看文件块大小 (可以参看[ID:360032.1]How to detect and fix ...

  8. JQuery常用函数及功能小结--转载

    1.文档加载完成执行函数 $(document).ready(function(){  alert("开始了"); }); 2.添加/删除CSS类 $("#some-id ...

  9. 在 SQL Server 中查询EXCEL 表中的数据遇到的各种问题

    SELECT * FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0','Data Source="D:\KK.xls";User ID=A ...

  10. 删除表数据drop、truncate和delete的用法

    说到删除表数据的关键字,大家记得最多的可能就是delete了 然而我们做数据库开发,读取数据库数据.对另外的两兄弟用得就比较少了 现在来介绍另外两个兄弟,都是删除表数据的,其实也是很容易理解的 老大- ...