hdu 2825 Wireless Password(ac自己主动机&dp)
Wireless Password
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4022 Accepted Submission(s): 1196
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.
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.
10 2 2
hello
world
4 1 1
icpc
10 0 0
0 0 0
2
1
14195065
#include<algorithm>
#include<iostream>
#include<string.h>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const double PI=acos(-1.0);
const int mod=20090717;
const int md=150;
const int ssz=26;
const int maxn=30;
int ch[md][ssz],val[md],f[md],last[md];
int sz,dp[maxn][md][1<<11],one[1<<11],bi[11];
int idx(char c) { return c-'a'; }
void init()
{
sz=1;
val[0]=0;
memset(ch[0],0,sizeof ch[0]);
}
void Insert(char *s,int v)
{
int u=0,n=strlen(s);
for(int i=0; i<n; i++)
{
int c=idx(s[i]);
if(!ch[u][c])
{
memset(ch[sz],0,sizeof ch[sz]);
val[sz]=0;
ch[u][c]=sz++;
}
u=ch[u][c];
}
val[u]=v;
}
void getf()
{
queue<int> q;
int u,v,c,r;
f[0]=0;
for(c=0;c<ssz;c++)
{
u=ch[0][c];
if(u)
{
f[u]=0;
q.push(u);
last[u]=0;
}
}
while(!q.empty())
{
r=q.front();
q.pop();
val[r]|=val[f[r]];
for(c=0;c<ssz;c++)
{
u=ch[r][c];
if(!u)
{
ch[r][c]=ch[f[r]][c];
continue;
}
q.push(u);
v=f[r];
while(v&&!ch[v][c])
v=f[v];
f[u]=ch[v][c];
}
}
}
void solve(int n,int k,int ms)
{
int i,j,s,c,v,ns,ans;
getf();
for(i=0;i<=n;i++)
for(j=0;j<sz;j++)
for(s=0;s<ms;s++)
dp[i][j][s]=0;
dp[0][0][0]=1;
for(i=0;i<n;i++)
for(j=0;j<sz;j++)
for(s=0;s<ms;s++)
{
if(!dp[i][j][s])
continue;
for(c=0;c<ssz;c++)
{
v=ch[j][c],ns=s|val[v];
dp[i+1][v][ns]=(dp[i+1][v][ns]+dp[i][j][s])%mod;
}
}
ans=0;
for(s=0;s<ms;s++)
{
if(one[s]<k)
continue;
for(i=0;i<sz;i++)
ans=(ans+dp[n][i][s])%mod;
}
printf("%d\n",ans);
}
int getone(int x)
{
int c=0;
while(x)
{
c+=x&1;
x>>=1;
}
return c;
}
int main()
{
int i,n,m,k;
char magic[20]; bi[0]=1;
for(i=1;i<11;i++)
bi[i]=bi[i-1]<<1;
for(i=0;i<bi[10];i++)
one[i]=getone(i);
while(scanf("%d%d%d",&n,&m,&k),n||m||k)
{
init();
for(i=0;i<m;i++)
{
scanf("%s",magic);
Insert(magic,bi[i]);
}
solve(n,k,bi[m]);
}
return 0;
}
hdu 2825 Wireless Password(ac自己主动机&dp)的更多相关文章
- HDU 2825 Wireless Password (AC自己主动机,DP)
pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...
- HDU - 2825 Wireless Password(AC自己主动机+DP)
Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...
- POJ 3691 & HDU 2457 DNA repair (AC自己主动机,DP)
http://poj.org/problem?id=3691 http://acm.hdu.edu.cn/showproblem.php?pid=2457 DNA repair Time Limit: ...
- HDU 2825 Wireless Password(AC自动机+DP)
题目链接 做题, #include <cstdio> #include <string> #include <cstring> using namespace st ...
- [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem
意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...
- ZOJ 3494 BCD Code (AC自己主动机 + 数位DP)
题目链接:BCD Code 解析:n个病毒串.问给定区间上有多少个转换成BCD码后不包括病毒串的数. 很奇妙的题目. . 经典的 AC自己主动机 + 数位DP 的题目. 首先使用AC自己主动机,得到b ...
- HDU 2896 病毒侵袭 (AC自己主动机)
pid=2896">http://acm.hdu.edu.cn/showproblem.php?pid=2896 病毒侵袭 Time Limit: 2000/1000 MS (Java ...
- hdu 2222 Keywords Search ac自己主动机
点击打开链接题目链接 Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDU 2896 病毒侵袭 AC自己主动机题解
本题是在text里面查找key word的增强版.由于这里有多个text. 那么就不能够简单把Trie的叶子标志记录改动成-1进行加速了,能够使用其它技术.我直接使用个vis数组记录已经訪问过的节点, ...
随机推荐
- iOS 8 Auto Layout界面自动布局系列5-自身内容尺寸约束、修改约束、布局动画
首先感谢众多网友的支持,最近我实在是事情太多,所以没有写太多.不过看到大家的反馈和评价,我还是要坚持挤出时间给大家分享我的经验.如果你对我写的东西有任何建议.意见或者疑问,请到我的CSDN博客留言: ...
- [Android算法] bitmap 将图片压缩到指定的大小
Bitmap压缩到指定大小: private void imageZoom() {//图片允许最大空间 单位:KBdouble maxSize =400.00;//将bitmap放至数组中,意在bit ...
- C#使用checked关键字处理"溢出"错误
代码如下: private void btnCalculate_Click(object sender, EventArgs e) { byte num1, num2;//定义两个byte变量 if( ...
- [MVC4-基礎] 連動DropDownList - 使用jQuery、JSON
剛開始學MVC4,以下是一些基礎的學習筆記! 先展示一下結果: 1.選擇申請部門 2.選好後申請部門鎖住防止USER修改並載入該部門所擁有的設備類型 一.資料庫 dept mf_fx 二.View ( ...
- Asp.Net HttpApplication 事件汇总
Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...
- Java的Object对象
Object对象是除了基础对象之外,所有的对象都需要继承的父对象,包括数组也继承了Object Object里面的关键函数罗列如下: clone();调用该函数需要实现 Cloneable,否则会抛出 ...
- Winform 无边框随意拖动【转载】
本篇技术内容转载自:http://www.cnblogs.com/ap0606122/archive/2012/10/23/2734964.html using System; using Syste ...
- Invalid content was found starting with element 'taglib'”
今天在使用struts-menu制作菜单,在web.xml中写入 <taglib> <taglib-uri>/WEB-INF/struts-menu.tld</ ...
- iOS中UISearchBar(搜索框)使用总结
http://my.oschina.net/u/2340880/blog/509756
- Gora官方范例
参考官方文档:http://gora.apache.org/current/tutorial.html 项目代码见:https://code.csdn.net/jediael_lu/mygoradem ...