hdu2825Wireless Password
地址: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
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.
hello
world
4 1 1
icpc
10 0 0
0 0 0
1
14195065
#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的更多相关文章
- 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][ ...
- 【hdu2825-Wireless Password】AC自动机+DP
http://acm.hust.edu.cn/vjudge/problem/16883 题意:要构造一个长度为n的字符串,然后有m模板串构成一个集合(m<=10),构造出来的字符串至少含有k种模 ...
- AC自动机小结
专题链接 第一题--hdu2222 Keywords Search ac自动机的模板题,入门题. 题解 第二题--hdu2896 病毒侵袭 一类病毒的入门题,类似模板 题解 第三题--hdu3 ...
- 打开程序总是会提示“Enter password to unlock your login keyring” ,如何成功关掉?
p { margin-bottom: 0.1in; line-height: 120% } 一.一开始我是按照网友所说的 : rm -f ~/.gnome2/keyrings/login.keyrin ...
- your password has expired.to log in you must change it
今天应用挂了,log提示密码过期.客户端连接不上. 打开mysql,执行sql语句提示密码过期 执行set password=new password('123456'); 提示成功,但客户端仍然连接 ...
- MySql Access denied for user 'root'@'localhost' (using password:YES) 解决方案
关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入"mysql -uroot -pmyadmin"后出现以下错 ...
- [上架] iOS "app-specific password" 上架问题
当你的 Apple ID 改用双重认证密码时,上架 iOS App 需要去建立一个专用密码来登入 Apple ID 才能上架. 如果使用 Application Loader 上传时,得到这个讯息: ...
- [LeetCode] Strong Password Checker 密码强度检查器
A password is considered strong if below conditions are all met: It has at least 6 characters and at ...
- 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: 问题原因: ...
随机推荐
- CAEmitterCell 和 CAEmitterLayer具体解释
一.在 UIKit 中,粒子系统由两部分组成: 1· 一个或多个 CAEmitterCells :发射器电池能够看作是单个粒子的原型(比如,一个单一的粉扑在一团烟雾).当散发出一个粒子,U ...
- Python背景知识——学习笔记
诞生于1989圣诞节,阿姆斯特丹.Guido van Rossum(吉多·范罗苏姆). Python Python:解释型.面向对象.动态数据类型 的 高级程序设计语言. 解释型语言:运行的时候将程序 ...
- MFC中给控件添加变量,DoDataExchange中
DoDataExchange函数其实是一项数据动态绑定技术.比如你在写动态按钮过程中须对按钮添加变量时,怎么添加?控件类已经写好了,其变量是已经固定的.你要添加新的变量就要用到DoDataExchan ...
- 数据仓库与BI面试常见题目
一. 数据库 1. Oracle数据库,视图与表的区别?普通视图与物化视图的区别?物化视图的作用?materialized view 答:a:视图是虚拟表,提高了表的安全性,视图没有实际物理空间,而表 ...
- Jquery-easyUi------(布局)
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %> <! ...
- php 实现Iterator 接口
<?php class MyIterator implements Iterator{ private $var = array(); public function __construct($ ...
- 使用jq获取文字的宽度
获取字符串的长度很简单,但是如何获取一个字符串的字体宽度却是一个不太好操作的问题,今天查阅了许多资料,终于找到了解决方法: 1.首先,需要添加一个标签,HTML代码如下: <body> & ...
- Struts2数据验证与使用Java代码进行数据验证
Struts2数据验证 使用Java代码进行数据验证 重写ActionSupport的validate()方法 对Action类的中所有请求处理方法都会进行验证! 对Action类的数据属性进行检查, ...
- Python: 使用pip升级所有包
pip 当前内建命令并不支持升级所有已安装的Python模块. 列出当前安装的包: pip list 列出可升级的包: pip list --outdate 升级一个包: pip install ...
- Myeclipse中js总是报错
1.右键选择 MyEclipse-->Exclude From Validation .2.再右键选择 MyEclipse-->Run Validation 即可.