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: 问题原因: ...
随机推荐
- Linux服务器的最大内存和CPU数
从网上查了很多资料.总算把linux下的内存和cpu个数搞清楚了.个人觉得使用linux系统的朋友都应该了解下.先公布如下,如有错误,请反馈给我.谢谢!! Linux系统/服务器能够支持的最大内存和C ...
- android classloader双亲托付模式
概述 ClassLoader的双亲托付模式:classloader 按级别分为三个级别:最上级 : bootstrap classLoader(根类载入器) : 中间级:extension class ...
- Hibernate_day01--Hibernate配置文件详解_核心api
Hibernate映射配置文件(重点) 1 映射配置文件名称和位置没有固定要求 2 映射配置文件中,标签name属性值写实体类相关内容 (1)class标签name属性值实体类全路径 (2)id标签和 ...
- iOS开发之--TableViewCell重用机制避免重复显示问题
常规配置如下 当超过tableView显示的范围的时候 后面显示的内容将会和前面重复 // 这样配置的话超过页面显示的内容会重复出现 - (UITableViewCell *)tableView:(U ...
- SmartGit Mac、Liunx、Windows过期后破解方法
根据自己的操作系统,进入相应的文件夹 ,可能还有一个版本号的文件夹,再进入 Windows: %APPDATA%\syntevo\SmartGit\ OS X: ~/Library/Preferenc ...
- 81、去除标题栏 Activity 和 AppCompatActivity
[Activity ] requestWindowFeature(Window.FEATURE_NO_TITLE); [AppCompatActivity] getSupportActionBar() ...
- C#三种字符串拼接方法的效率对比
C#字符串拼接的方法常用的有:StringBuilder.+.string.Format.List<string>.使用情况不同,效率不同. 1.+的方式 string sql = &qu ...
- JS如何获取url查询字符串的键和值?
/** * 根据url查询字符串里的键名获取其值 */function getSearchString(key, search) { // 获取URL中?之后的字符 var str = search; ...
- ehcache 的 配置文件: ehcache.xml的认识
<ehcache> <!-- 指定一个目录:当 EHCache 把数据写到硬盘上时, 将把数据写到这个目录下. --> <diskStore path="d:\ ...
- c# window窗口
代码功能 一.隐藏当前窗口 this.Hide();//隐藏当前窗口 二.调用计算机自带 System.Diagnostics.Process.Start("calc.exe"); ...