地址:http://acm.hdu.edu.cn/showproblem.php?pid=2825

题目:

Wireless Password

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6862    Accepted Submission(s): 2279

Problem 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
 
Source
 
 
思路:
  dp[i][j]表示长度为i的串走到j节点时的答案的数量。
 #include <queue>
#include <cstring>
#include <cstdio>
using namespace std; const int INF=0x3f3f3f3f;
struct AC_auto
{
const static int LetterSize = ;
const static int TrieSize = LetterSize * ( 1e3 + ); int tot,root,fail[TrieSize],end[TrieSize],next[TrieSize][LetterSize];
int dp[][][<<];
int newnode(void)
{
memset(next[tot],-,sizeof(next[tot]));
end[tot] = ;
return tot++;
} void init(void)
{
tot = ;
root = newnode();
} int getidx(char x)
{
return x-'a';
} void insert(char *ss,int x)
{
int len = strlen(ss);
int now = root;
for(int i = ; i < len; i++)
{
int idx = getidx(ss[i]);
if(next[now][idx] == -)
next[now][idx] = newnode();
now = next[now][idx];
}
end[now]|=x;
} void build(void)
{
queue<int>Q;
fail[root] = root;
for(int i = ; i < LetterSize; i++)
if(next[root][i] == -)
next[root][i] = root;
else
fail[next[root][i]] = root,Q.push(next[root][i]);
while(Q.size())
{
int now = Q.front();Q.pop();
for(int i = ; i < LetterSize; i++)
if(next[now][i] == -) next[now][i] = next[fail[now]][i];
else
{
fail[next[now][i]] = next[fail[now]][i];
end[next[now][i]]|=end[fail[next[now][i]]];
Q.push(next[now][i]);
}
}
} int match(char *ss)
{
int len,now,res;
len = strlen(ss),now = root,res = ;
for(int i = ; i < len; i++)
{
int idx = getidx(ss[i]);
int tmp = now = next[now][idx];
while(tmp)
{
res += end[tmp];
end[tmp] = ;//按题目修改
tmp = fail[tmp];
}
}
return res;
} int go(int n,int m,int kd)
{
int ans=;
memset(dp,,sizeof dp);
dp[][][]=;
for(int i=,mx=<<m;i<n;i++)
for(int j=;j<tot;j++)
for(int k=;k<mx;k++)
for(int p=;p<LetterSize&&dp[i][j][k];p++)
{
dp[i+][next[j][p]][k|end[next[j][p]]]+=dp[i][j][k];
if(dp[i+][next[j][p]][k|end[next[j][p]]]>=)
dp[i+][next[j][p]][k|end[next[j][p]]]-=;
}
for(int i=,mx=<<m;i<tot;i++)
for(int j=;j<mx;j++)
{
int cnt=;
for(int k=;k<m;k++)
if(j&(<<k))
cnt++;
if(cnt>=kd) ans+=dp[n][i][j];
if(ans>=) ans-=;
}
return ans;
}
void debug()
{
for(int i = ;i < tot;i++)
{
printf("id = %3d,fail = %3d,end = %3d,chi = [",i,fail[i],end[i]);
for(int j = ;j < LetterSize;j++)
printf("%3d",next[i][j]);
printf("]\n");
}
}
};
AC_auto ac;
char ss[];
int main(void)
{
int n,k,m;
while(~scanf("%d%d%d",&n,&m,&k)&&(m||n||k))
{
ac.init();
for(int i=;i<m;i++)
scanf("%s",ss),ac.insert(ss,<<i);
ac.build();
printf("%d\n",ac.go(n,m,k));
}
return ;
}
 

hdu2825Wireless Password的更多相关文章

  1. hdu2825Wireless Password(ac+dp)

    链接 状压dp+ac dp[i+1][next[j]][st|tt]表示第i+1长度结点为next[j]状态为st|tt的时候的ans; dp[i+1][next[j]][st|tt]+=dp[i][ ...

  2. 【hdu2825-Wireless Password】AC自动机+DP

    http://acm.hust.edu.cn/vjudge/problem/16883 题意:要构造一个长度为n的字符串,然后有m模板串构成一个集合(m<=10),构造出来的字符串至少含有k种模 ...

  3. AC自动机小结

    专题链接 第一题--hdu2222 Keywords Search ac自动机的模板题,入门题.  题解 第二题--hdu2896 病毒侵袭   一类病毒的入门题,类似模板  题解 第三题--hdu3 ...

  4. 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?

    p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...

  5. your password has expired.to log in you must change it

    今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...

  6. MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案

    关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...

  7. [上架] iOS "app-specific password" 上架问题

    当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...

  8. [LeetCode] Strong Password Checker 密码强度检查器

    A password is considered strong if below conditions are all met: It has at least 6 characters and at ...

  9. mysql 错误 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number 解决办法

    MySQL创建用户(包括密码)时,会提示ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number: 问题原因: ...

随机推荐

  1. 兔子--android中百度地图的开发

    效果: API Key的申请地址:http://lbsyun.baidu.com/apiconsole/key 申请注意事项: 安全码:以下界面的SHA1  fingerprint值+;+包名 比如: ...

  2. ANSI、ASCII、GB2312、GBK

    ASCII 在计算机中,所有的数据在存储和运算时都要使用二进制数表示(因为计算机用高电平和低电平分别表示1和0),例如,像a.b.c.d这样的52个字母(包括大写).以及0.1等数字还有一些常用的符号 ...

  3. XML Publiser For Excel Template

    1.XML Publisher定义数据 2.XML Publisher定义模板 模板类型选择Microsoft Excel,默认输出类型选择Excel,上传.xls模板 3.定义并发程序 4.定义请求 ...

  4. ios模拟器键盘不弹出

    本文转载至 http://blog.csdn.net/cerastes/article/details/39547967 xcode6键盘iPhone-Portrait-Numb不弹出Cant fin ...

  5. cocos2dx游戏--三国关羽传【角色扮演类】Demo的制作及实现

    项目地址:https://github.com/moonlightpoet/GuanYuZhuan 主要类及其对应效果: MainScene:菜单界面(用于选择不同剧本) StoryScene:故事界 ...

  6. JQZoom

    UI采用jQuery插件 习惯网购的朋友都深有体会.大部分皇冠级淘宝卖家都是图片控.京东商城的放大图效果也是吸引消费者的法宝之一.京东商城产品展示页支持多图切换并放大代码,放大功能的核心代码为jQzo ...

  7. 问道游戏-寻路CALL心得

    寻路CALL查找几种方法 第一种 bp send 在小地图上点击重点.看看是否断下 断下这是最简单的 第二种 查找用户当前坐标内存地址下写入断点 通过堆栈追溯 运气好也可以找到 第三种 查找终点坐标地 ...

  8. java开源模板引擎

      Velocity  Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义 ...

  9. application/x-protobuf payload加密 知乎

  10. 【python】常用函数

    使用list生成dict(可指定单条长度和数据类型,splen为4即为list中每4行组成dict中一条) def list2dict(srclist,splen,datatype):# dataty ...