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. careercup-数组和字符串1.1

    1.1 实现一个算法,确定一个字符串的所有字符是否全部不同.假设不允许使用额外的数据结构,又该如何处理? C++实现: #include<iostream> #include<str ...

  2. UDP 校检和和算法

    #include <Winsock2.h> #include <stdio.h> #define IP_HDRINCL 2 // Header is included with ...

  3. Android开发之ViewPager实现轮播图(轮播广告)效果的自定义View

    最近开发中需要做一个类似京东首页那样的广告轮播效果,于是采用ViewPager自己自定义了一个轮播图效果的View. 主要原理就是利用定时任务器定时切换ViewPager的页面. 效果图如下: 主页面 ...

  4. homework做了些什么?

    第一步:get_new_guid_uid_pairs_{$ymd} 参数是时间和100上的文件. 那么100上的文件是从哪里来的呢? 我们进入到100机器上,打开root权限下的cron,看到如下内容 ...

  5. HTML语言语法大全

    (文章转载至博客园 dodo-yufan) <! - - ... - -> 註解 <!> 跑馬燈 <marquee>...</marquee>普通捲動  ...

  6. js 配置基础启动文件

    页面启动文件boot.js,获取存放该文件的路径,放置通用的css,js代码,方便html页面调用. __CreateJSPath = function (js) { var scripts = do ...

  7. 从腾讯QQ升级游戏之“快速加入游戏”功能的实现缺陷看C/S之间如何正确分配相关协作

    转载:http://space.itpub.net/17007506/viewspace-615570 笔者在闲暇时,偶尔会登录腾讯QQGame玩玩升级游戏.这确实是一款非常优秀的软件作品,腾讯的开发 ...

  8. Android SQLite ORM框架greenDAO在Android Studio中的配置与使用

    博客: 安卓之家 微博: 追风917 CSDN: 蒋朋的家 简书: 追风917 博客园: 追风917 # 说明 greenDAO是安卓中处理SQLite数据库的一个开源的库,详情见其官网:我是官网 详 ...

  9. My97 DatePicker 选择时间后弹出选择的时间

    项目中用到这个时间插件,注册用户时可以选中永久和选择时间,二者是互斥关系, 所以在选择时间插件时,需要绑定一个事件,所以看到了这个插件: <input id="yydate" ...

  10. js中push()方法

    直接上代码: var roleIdsTemp = []; $("#addRole .modalcheckbox-all").each(function(key, value) {  ...