【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 ...
随机推荐
- Strtus2标签之<s:url>
Strtus2标签<s:url> 在没有使用Struts2的时候可以使用el来进行url传参.而在Struts2中不推荐使用el(其实在Struts2.0.0.11之后就不再支持el)而推 ...
- 【Android】数据库的简单应用——升级数据库
假如我们已经创建好了一个数据库,随着功能需求的增加,想在数据库中再添加一个表,如果直接在之前的代码中插入一个表,会发现创建表失败,这是因为该数据库已经存在.该如何解决呢? 1.卸载程序,重新编译安装. ...
- Android - Binder驱动
以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删): http://blog.csdn.net/luosh ...
- Java中的I/O流
import java.io.*//生成代表输入流的对象fis=new FileInputStream("e:/src/from.txt") //生成代表输出流的对象 fos=ne ...
- .net数据传递的格式
1 Object 返回数据库查询后的单个值 public object LoadBusinessScopeById(int id) { string sql = "select [name] ...
- Table显示滚动条
Table显示滚动条,要先把table放到一个div中,div的长度和宽度要固定,控制overflow属性为scroll <div style="width:700px; height ...
- Sql解锁 数据库死锁检测
USE [DataBaseName]GO/****** Object: StoredProcedure [dbo].[sp_check_deadlock] Script Date: 07/04 ...
- js基础知识之_流程控制语句
javascript 流程控制 流程控制:就是程序代码执行顺序 流程控制:通过规定的语句让程序代码有条件的按照一定的方式执行 顺序结构 按照书写顺序来执行,是程序中最基本的流程结构 选择结构(分支结构 ...
- Oracle 11g 新特性(一)-- 虚拟列
数据库版本: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Oracle11g 增加了虚拟列的新特性, 具体说明如 ...
- 数据库学习(整理)----6--Oracle如何快速备份和多次备份数表数据
1.说明: 这里假设一种应用场景! 假设,银行系统中有大量的数据需要及时备份,如何才能快速高效呢! 条件需求: (1).不能设置同步锁(设置的会影响银行正常业务进行!使得银行系统处于维护状态,这是不 ...