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

Description

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
 

【题意】

  有个人想破解他邻居的密码,他邻居告诉了一些关于这个密码的信息,并且给他一个单词集合,他用这些信息判断一下最少有多少密码。
  1->, 所有的密码都是有小写字母组成。
  2->,密码的长度是 n (1<= n <=25)。
  3->,密码至少包含 k 种字符集里面的单词。
 
  比如,给集合{"she", "he"},单词长度是3,最少包含两个单词的密码,很明显只能是“she”(题目表述的不清楚)。
 
【分析】

  先建AC自动机。
  DP部分 令 dp[i][j][l] 表示长度为 i ,跑到自动机节点 j ,已经包含单词为集合l的方案数。(因为k比较小)
 
代码如下:
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define Maxn 1010
#define Maxl 1010
#define INF 0xfffffff
#define Mod 20090717 int n,m,ak;
char s[]; struct node
{
int cnt,fail,mark;
int son[];
}t[Maxn];int tot;//=0;
int num;
int p[]; void upd(int x)
{
t[x].cnt=;t[x].mark=;
memset(t[x].son,,sizeof(t[x].son));
} int mymin(int x,int y) {return x<y?x:y;} void read_trie()
{
scanf("%s",s+);
int len=strlen(s+);
int now=;
for(int i=;i<=len;i++)
{
int ind=s[i]-'a'+;
if(!t[now].son[ind])
{
t[now].son[ind]=++tot;
upd(tot);
}
now=t[now].son[ind];
if(i==len)
{
t[now].mark=<<(++num)-;
}
}
} queue<int > q;
void build_AC()
{
while(!q.empty()) q.pop();
q.push();//inq[0]=1;
while(!q.empty())
{
int x=q.front();q.pop();
for(int i=;i<=;i++)
{
if(t[x].son[i])
{
t[t[x].son[i]].fail=x?t[t[x].fail].son[i]:;
q.push(t[x].son[i]);
}
else t[x].son[i]=t[t[x].fail].son[i];
t[x].mark|=t[t[x].fail].mark;
}
}
} bool check(int x)
{
int h=;
for(int i=;i<=num;i++) if(x&(<<i-)) h++;
if(h>=ak) return ;
return ;
} int f[][][];
void dp()
{
for(int i=;i<=n;i++)
for(int j=;j<=tot;j++)
for(int l=;l<=(<<num)-;l++) f[i][j][l]=;
f[][][]=;
for(int i=;i<=n;i++)
for(int j=;j<=tot;j++)
for(int l=;l<=(<<num)-;l++) if(f[i-][j][l]!=)
{
for(int k=;k<=;k++)
{
f[i][t[j].son[k]][l|t[t[j].son[k]].mark]=(f[i][t[j].son[k]][l|t[t[j].son[k]].mark]+f[i-][j][l])%Mod;
}
}
int ans=;
for(int i=;i<=(<<num)-;i++) if(check(i))
{
for(int j=;j<=tot;j++) ans=(ans+f[n][j][i])%Mod;
}
printf("%d\n",ans);
} void init()
{
tot=;num=;
upd();
for(int i=;i<=m;i++)
{
read_trie();
}
build_AC();
} int main()
{
int kase=;
while()
{
scanf("%d%d%d",&n,&m,&ak);
if(n==&&m==&&ak==) break;
init();
dp();
}
return ;
}

[HDU2825]

2016-07-11 14:04:35

【HDU2825】Wireless Password (AC自动机+状压DP)的更多相关文章

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

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

  2. hdu2825 Wireless Password(AC自动机+状压dp)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission ...

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

    题目大意:给一系列字符串,用小写字母构造出长度为n的至少包含k个字符串的字符串,求能构造出的个数. 题目分析:在AC自动机上走n步,至少经过k个单词节点,求有多少种走法. 代码如下: # includ ...

  4. hdu_2825_Wireless Password(AC自动机+状压DP)

    题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...

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

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

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

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

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

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

  8. zoj3545Rescue the Rabbit (AC自动机+状压dp+滚动数组)

    Time Limit: 10 Seconds      Memory Limit: 65536 KB Dr. X is a biologist, who likes rabbits very much ...

  9. hdu 4057--Rescue the Rabbit(AC自动机+状压DP)

    题目链接 Problem Description Dr. X is a biologist, who likes rabbits very much and can do everything for ...

随机推荐

  1. magic_quotes_runtime(魔术引号开关)

    我们可以通过以下代码来探测php环境中magic_quotes_runtime是否开启: magic_runtime.php 源代码如下: <?php //当magic_quotes_runti ...

  2. 基于 CoreText 实现的高性能 UITableView

    引起UITableView卡顿比较常见的原因有cell的层级过多.cell中有触发离屏渲染的代码(譬如:cornerRadius.maskToBounds 同时使用).像素是否对齐.是否使用UITab ...

  3. Android(java)学习笔记182:保存数据到SD卡 (附加:保存数据到内存)

    1. 如果我们要想读写数据到SD卡中,首先必须知道SD的路径: File file = new File(Environment.getExternalStorageDirectory()," ...

  4. Windows Server 2008 R2 域控制器部署指南

    一.域控制器安装步骤: 1.装 Windows Server 2008 R2并配置计算机名称和IP地址(见 附录一) 2.点击“开始”,在“搜索程序和文件”中输入Dcpromo.exe后按回车键: 3 ...

  5. jquery自调用匿名函数解析

    alert("undefined" in window);        (function (window, undefined) {            //构造jQuery ...

  6. Http,Https(SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2的配置和使用 分类: ASP.NET 2014-11-05 12:51 97人阅读 评论(0) 收藏

    下载地址1:https://securityswitch.googlecode.com/files/SecuritySwitch%20v4.2.0.0%20-%20Binary.zip 下载地址2:h ...

  7. query 防止ajax重复提交

    项目用到js了,首选jquery,能用库用库,原则. 碰到重复提交的问题,禁止住才行.百度google,还是Google给力. 知乎上有个高人,总结了四种,利用Jquery .post方法返回jqXH ...

  8. 'EntityValidationErrors' property for more details

    很多小猿遇到这个Exception 的时候,都会有点无厘头.这个时候最好try-- catch下,找到出错的地方.本人习惯在页面上加个lable标签,把exc msg(exception messag ...

  9. mahout分类

    分类看起来比聚类和推荐麻烦多了 分类算法与聚类和推荐算法的不同:必须是有明确结果的,必须是有监督的,主要用于预测和检测 Mahout的优势 mahout的分类算法对资源的要求不会快于训练数据和测试数据 ...

  10. 使用jQuery播放/暂停 HTML5视频

    文章来自:http://blog.okbase.net/jquery2000/archive/4485.html 我尝试用jQuery控制HTML5视频,两个视频分别在两个tab中,我希望点中tab后 ...