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: 问题原因: ...
随机推荐
- sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)
Clockwise Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...
- 获取软件的apk包名、查看手机设备名称等
获取软件的apk包名 1.下载aapt,这里使用的是SDK自带的aapt,找到SDK路径下面的aapt.exe,本机路径:E:\downloads\android-sdk_r23.0.2-window ...
- 使用 composer 下载更新卸载类库
前言:要下载什么包,可以去 https://packagist.org/ 找一下包名及其版本信息 1)配置composer.json文件,并使用composer install 命令下载类包,下面以下 ...
- jedispool 连 redis
java端在使用jedispool 连接redis的时候,在高并发的时候经常卡死,或报连接异常,JedisConnectionException,或者getResource 异常等各种问题 在使用je ...
- MCU相关知识
一个处理器达到 200 DMIPS的性能,这是个什么概念? DMIPS全称叫Dhrystone MIPS 这项测试是用来计算同一秒内系统的处理能力,它的单位以百万来计算,也就是(MIPS) 上面的意思 ...
- [素数个数模板] HDU 5901 Count primes
#include<cstdio> #include<cmath> using namespace std; #define LL long long ; bool np[N]; ...
- 在input文本框中存入对象格式的数据
<input id="teaching" type="hidden" name="teachingProgram" /> JQ: ...
- 160314、MVC设计模式
MVC的由来 精彩内容 MVC模式最早由Trygve Reenskaug在1978年提出 ,是施乐帕罗奥多研究中心(Xerox PARC)在20世纪80年代为程序语言Smalltalk发明的一种软件设 ...
- Action请求流程分析
Strut2流程分析-----从请求到Action方法() 首先请求会调用strutsPrepareAndExcuteFliter----(这个就是我们在web.xml文件中所配置的那个拦截器吧,所有 ...
- linLINUX中常用操作命令
LINUX中常用操作命令 Linux简介及Ubuntu安装 常见指令 系统管理命令 打包压缩相关命令 关机/重启机器 Linux管道 Linux软件包管理 vim使用 用户及用户组管理 文件权限管理 ...