//我感觉这题不如叫你不看代码就不知道题干在说啥,强烈吐槽

Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless network in the building. Liyuan did not know the password of the network, but he got some important information from his neighbor. He knew the password consists only of lowercase letters 'a'-'z', and he knew the length of the password. Furthermore, he got a magic word set, and his neighbor told him that the password included at least k words of the magic word set (the k words in the password possibly overlapping).

For instance, say that you know that the password is 3 characters long, and the magic word set includes 'she' and 'he'. Then the possible password is only 'she'.

Liyuan wants to know whether the information is enough to reduce the number of possible passwords. To answer this, please help him write a program that determines the number of possible passwords.

 
Input
There will be several data sets. Each data set will begin with a line with three integers n m k. n is the length of the password (1<=n<=25), m is the number of the words in the magic word set(0<=m<=10), and the number k denotes that the password included at least k words of the magic set. This is followed by m lines, each containing a word of the magic set, each word consists of between 1 and 10 lowercase letters 'a'-'z'. End of input will be marked by a line with n=0 m=0 k=0, which should not be processed.
 
Output
For each test case, please output the number of possible passwords MOD 20090717.
 
Sample Input
10 2 2
hello
world
4 1 1
icpc
10 0 0
0 0 0
 
Sample Output
2
1
14195065
 
 
 
http://blog.csdn.net/braketbn/article/details/50650341   //参考的代码
 
 
-------------------------------手写的代码
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,k,dp[30][108][1100],cnt[1100];
const int mod=20090717;
struct AC
{
    int ch[108][26],fail[108],val[108],sz,rt;
    void init()
    {
        sz=rt=0;
        memset(ch[rt],-1,sizeof(ch[rt]));
    }
    void insert(char *str,int c)
    {
        int u=rt,len=strlen(str);
        for(int i=0; i<len; ++i)
        {
            if(ch[u][str[i]-'a']==-1)
            {
                ++sz;
                memset(ch[sz],-1,sizeof(ch[sz]));
                val[sz]=0;
                ch[u][str[i]-'a']=sz;
            }
            u=ch[u][str[i]-'a'];
        }
        val[u]=1<<c;
    }
    void build()
    {
        queue<int>Q;
        int u=rt;
        for(int i=0; i<26; ++i)
        {
            if(ch[u][i]==-1) ch[u][i]=rt;
            else
            {
                fail[ch[u][i]]=rt;
                Q.push(ch[u][i]);
            }
        }
        while(!Q.empty())
        {
            u=Q.front();
            Q.pop();
            val[u]|=val[fail[u]];
            for(int i=0; i<26; ++i)
            {
                if(ch[u][i]==-1) ch[u][i]=ch[fail[u]][i];
                else
                {
                    fail[ch[u][i]]=ch[fail[u]][i];
                    Q.push(ch[u][i]);
                }
            }
        }
    }
} ac;
char s[55];
int main()
{
    for(int i=0; i<1024; ++i) cnt[i]=__builtin_popcount(i);//黑科技
    while(scanf("%d%d%d",&n,&m,&k),n||m||k)
    {
        ac.init();
        for(int i=0; i<m; ++i)
        {
            scanf("%s",s);
            ac.insert(s,i);
        }
        ac.build();
        memset(dp,0,sizeof(dp));
        dp[0][0][0]=1;
        int ed=1<<m;
        for(int i=0; i<=n; ++i) for(int j=0; j<=ac.sz; ++j) for(int k=0; k<ed; ++k)
                {
                    if(!dp[i][j][k]) continue;
                    for(int l=0; l<26; ++l)
                    {
                        int u=ac.ch[j][l];
                        dp[i+1][u][ac.val[u]|k]+=dp[i][j][k];
                        dp[i+1][u][ac.val[u]|k]%=mod;
                    }
                }
        int ans=0;
        for(int i=0; i<=ac.sz; ++i) for(int j=0; j<ed; ++j) if(cnt[j]>=k)
                    ans=(ans+dp[n][i][j])%mod;
        printf("%d\n",ans);
    }
}

HDU2825AC自动机+状压的更多相关文章

  1. hdu 2825 aC自动机+状压dp

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

  2. hdu 6086 -- Rikka with String(AC自动机 + 状压DP)

    题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...

  3. [BZOJ1559]密码 AC自动机+状压

    问题 K: [JSOI2009]密码 时间限制: 1 Sec  内存限制: 64 MB 题目描述 众所周知,密码在信息领域起到了不可估量的作用.对于普通的登陆口令,唯一的破解 方法就是暴力破解一逐个尝 ...

  4. bzoj 1212: [HNOI2004]L语言 AC自动机+状压

    为什么这道题网上所有题解写的都是N*Len的trie树的暴力啊,4E的复杂度... 为什么暴力还跑这么快啊TAT.. 有一个O(Len)的做法就是先把AC自动机建出来,因为每个字典串的长度很小,所以我 ...

  5. [HNOI2006]最短母串问题——AC自动机+状压+bfs环形处理

    Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T的子串. 32MB Input 第一行是一个正整数n(n< ...

  6. BZOJ1559 [JSOI2009]密码 【AC自动机 + 状压dp】

    题目链接 BZOJ1559 题解 考虑到这是一个包含子串的问题,而且子串非常少,我们考虑\(AC\)自动机上的状压\(dp\) 设\(f[i][j][s]\)表示长度为\(i\)的串,匹配到了\(AC ...

  7. UVALive - 4126 Password Suspects (AC自动机+状压dp)

    给你m个字符串,让你构造一个字符串,包含所有的m个子串,问有多少种构造方法.如果答案不超过42,则按字典序输出所有可行解. 由于m很小,所以可以考虑状压. 首先对全部m个子串构造出AC自动机,每个节点 ...

  8. POJ1699【AC自动机+状压DP_感言】

    萌新感言: 我的天呐! 因为是AC自动机的专题所以没有管别的...硬着头皮吃那份题解(代码)..[请戳简单美丽可爱的代码(没开玩笑)] 首先讲AC自动机: tag存的是以这个节点为后缀的字符串个数(已 ...

  9. [HNOI2006]最短母串 (AC自动机+状压)

    Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T的子串. Input 第一行是一个正整数n(n<=12) ...

  10. HDU 3247 Resource Archiver(AC自动机 + 状压DP + bfs预处理)题解

    题意:目标串n( <= 10)个,病毒串m( < 1000)个,问包含所有目标串无病毒串的最小长度 思路:貌似是个简单的状压DP + AC自动机,但是发现dp[1 << n][ ...

随机推荐

  1. Spring Boot JPA的查询语句

    文章目录 准备工作 Containing, Contains, IsContaining 和 Like StartsWith EndsWith 大小写不敏感 Not @Query Spring Boo ...

  2. Vue 2.x折腾记 - (17) 基于Ant Design Vue 封装一个配置式的表单组件

    前言 写了个类似上篇搜索的封装,但是要考虑的东西更多. 具体业务比展示的代码要复杂,篇幅太长就不引入了. 效果图 2019-04-25 添加了下拉多选的渲染,并搜索默认过滤文本而非值 简化了渲染的子组 ...

  3. python操作ftp文件

    from ftplib import FTP ftp = FTP('ftp.abc.com') ftp.login(user='username', passwd='********') ftp.cw ...

  4. 团队一致性的PHP开发环境之Docker

    docker php环境模型 docker 简介 Docker 是一个开源的应用容器引擎 让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现 ...

  5. 带权并查集--hdu3047 ZJnu stadium

    题意:给出一个n,m,n表示的是有n 个人,m表示的是 有m 对关系: 接下来输入的就是这m对关系,a,b,x:表示的是a,b相距x个距离:然后判断输入的是否与这个数的上面的数信息一致, 输出不一致的 ...

  6. [USACO1.3]虫洞wormhole

    题目描述 农夫约翰爱好在周末进行高能物理实验的结果却适得其反,导致N个虫洞在农场上(2<=N<=12,n是偶数),每个在农场二维地图的一个不同点. 根据他的计算,约翰知道他的虫洞将形成 N ...

  7. RobotFrameWork 自动化环境搭建(基于 python2.7)

    1.自动化工具安装顺序 robot Framework(两个RF框架) WXpython(不要更改安装路径,自动安装在python文件中) 安装依赖库 RF3.0 和 RF1.5.2.1 打开 rid ...

  8. E. Yet Another Task with Queens(分类思想)

    \(\color{Red}{描述}\) \(在n*n的棋盘上有m个K皇后,每个皇后可能被来自8个方向的其他皇后攻击\) \(每个皇后只可能被(0-8)只皇后攻击,分别求出被(0-8)只皇后攻击的皇后数 ...

  9. Lasso回归

    Lasso 是一个线性模型,它给出的模型具有稀疏的系数(sparse coefficients).它在一些场景中是很有用的,因为它倾向于使用较少参数的情况,能够有效减少给定解决方案所依赖变量的个数.因 ...

  10. Linux目录、文件的管理

    centos目录结构 ls / 查看根目录下有哪些文件或者目录 bin 可执行文件的目录 sbin 存放root用户可执行文件目录 etc 配置文件 boot 引导文件 home 普通用户宿主目录 l ...