【HDU2825】Wireless Password (AC自动机+状压DP)
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 2helloworld4 1 1icpc10 0 00 0 0Sample Output
2114195065
【题意】
#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)的更多相关文章
- HDU2825 Wireless Password —— AC自动机 + 状压DP
题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others) ...
- hdu2825 Wireless Password(AC自动机+状压dp)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- HDU-2825 Wireless Password(AC自动机+状压DP)
题目大意:给一系列字符串,用小写字母构造出长度为n的至少包含k个字符串的字符串,求能构造出的个数. 题目分析:在AC自动机上走n步,至少经过k个单词节点,求有多少种走法. 代码如下: # includ ...
- hdu_2825_Wireless Password(AC自动机+状压DP)
题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- BZOJ1559 [JSOI2009]密码 【AC自动机 + 状压dp】
题目链接 BZOJ1559 题解 考虑到这是一个包含子串的问题,而且子串非常少,我们考虑\(AC\)自动机上的状压\(dp\) 设\(f[i][j][s]\)表示长度为\(i\)的串,匹配到了\(AC ...
- HDU 3247 Resource Archiver(AC自动机 + 状压DP + bfs预处理)题解
题意:目标串n( <= 10)个,病毒串m( < 1000)个,问包含所有目标串无病毒串的最小长度 思路:貌似是个简单的状压DP + AC自动机,但是发现dp[1 << n][ ...
- zoj3545Rescue the Rabbit (AC自动机+状压dp+滚动数组)
Time Limit: 10 Seconds Memory Limit: 65536 KB Dr. X is a biologist, who likes rabbits very much ...
- hdu 4057--Rescue the Rabbit(AC自动机+状压DP)
题目链接 Problem Description Dr. X is a biologist, who likes rabbits very much and can do everything for ...
随机推荐
- 基于VMware为CentOS 6.5配置两个网卡
为CentOS 6.5配置两块网卡,一块是eth0,一块是eth1,下面以master为例 1.选择“master”-->“编辑虚拟机设置”,如下所示 2.单击“添加”,如下 3.选择“网络适配 ...
- ASP.NET Web API(一):使用初探,GET和POST数据
概述 REST(Representational State Transfer表述性状态转移)而产生的REST API的讨论越来越多,微软在ASP.NET中也添加了Web API的功能 项目建立 在安 ...
- Java基础知识强化之集合框架笔记58:Map集合之LinkedHashMap类的概述
1. LinkedHashMap类的概述 LinkedHashMap:Map接口的哈希表(保证唯一性) 和 链接(保证有序性)列表实现,具有可预知的迭代顺序. 2. 代码示例: package cn. ...
- POJ-3278(BFS)
题目: ...
- 第三部分 关于HHibernate中关键字ID的配置
实体类映射中,必须配置一个关键字,对应着数据表的关键字,大多数的实体类也都有一个属性表示类的唯一性,在实体类配置文件(.hbm.xml)中,<id>元素的就是这个作用. 一个完整的ID配置 ...
- Javascript基础学习(3)_对象和数组
一.对象是一种无序的属性集合,每个属性都有自己的名字和值. 1.创建对象 花括号内逗号分隔 var person = { "Name" : "LiCheng", ...
- java.sql.Date to java.util.Date
发这篇博文的题目可能无法直接表示内容,但是确实是java.sql.Date和java.util.Date. 今天在使用'net.sf.json.JSONObject'封装json数据的时候,碰到很奇怪 ...
- java获取远程网络图片文件流、压缩保存到本地
1.获取远程网路的图片 /** * 根据地址获得数据的字节流 * * @param strUrl * 网络连接地址 * @return */ public static byte[] getImage ...
- POJ_3143 验证“歌德巴赫猜想”
今天晚上的火车回家啦.所以提前更出来~.愉快的收拾我的包裹~滚回家吃半个月~胖几斤又要回学校啦~ T T这个假期虽然很忙.但是我觉得很有意义.很有价值~爱你们~ 描述 验证“歌德巴赫猜想”,即:任意一 ...
- Windows7 QT5.6.0(64位)使用mysql(64位)环境搭建详解
1 说明 使用环境为:Windows7 VS2015 QT5.6.0(64位),MYSQL 5.7.13(64位). 网上各种错误.模糊.抽象的资料,配置环境花了半天,痛定思痛,总结出来,方便后来人. ...