Wireless Password

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4022    Accepted Submission(s): 1196

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
 
Recommend
gaojie   |   We have carefully selected several similar problems for you:  2819 2824 2817 2823 2822 
 题意:
某人要去破译wifipassword。如今他已经知道password所有由小写字母组成。且password的长度n(1<=n<=25)。和m(0<=m<=10)个password中可能出现的串(magic)。每一个串长度不超过10.如今他已经知道password中这m个串至少出现了k个。能够覆盖出现。如今问你password可能有多少种。
思路:
因为是专门搜的ac自己主动机动规的题目。所以就直接往ac自己主动机动规上想了。这题的难点是确定出现magic中出现了多少个。考虑到m比較小。所以就直接壮压了。最后才取满足条件的状态即可了。
具体见代码:
#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自己主动机&amp;dp)的更多相关文章

  1. HDU 2825 Wireless Password (AC自己主动机,DP)

    pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...

  2. HDU - 2825 Wireless Password(AC自己主动机+DP)

    Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...

  3. POJ 3691 &amp; 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: ...

  4. HDU 2825 Wireless Password(AC自动机+DP)

    题目链接 做题, #include <cstdio> #include <string> #include <cstring> using namespace st ...

  5. [AC自己主动机+可能性dp] hdu 3689 Infinite monkey theorem

    意甲冠军: 给n快报,和m频率. 然后进入n字母出现的概率 然后给目标字符串str 然后问m概率倍的目标字符串是敲数量. 思维: AC自己主动机+可能性dp简单的问题. 首先建立trie图,然后就是状 ...

  6. ZOJ 3494 BCD Code (AC自己主动机 + 数位DP)

    题目链接:BCD Code 解析:n个病毒串.问给定区间上有多少个转换成BCD码后不包括病毒串的数. 很奇妙的题目. . 经典的 AC自己主动机 + 数位DP 的题目. 首先使用AC自己主动机,得到b ...

  7. HDU 2896 病毒侵袭 (AC自己主动机)

    pid=2896">http://acm.hdu.edu.cn/showproblem.php?pid=2896 病毒侵袭 Time Limit: 2000/1000 MS (Java ...

  8. hdu 2222 Keywords Search ac自己主动机

    点击打开链接题目链接 Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  9. HDU 2896 病毒侵袭 AC自己主动机题解

    本题是在text里面查找key word的增强版.由于这里有多个text. 那么就不能够简单把Trie的叶子标志记录改动成-1进行加速了,能够使用其它技术.我直接使用个vis数组记录已经訪问过的节点, ...

随机推荐

  1. C#基础之方法参数

    params params 关键字可以指定在参数数目可变处采用参数的方法参数. 在方法声明中的 params 关键字之后不允许任何其他参数,并且在方法声明中只允许一个 params 关键字 publi ...

  2. ASP.NET 根据现有动态页面生成静态Html

    现有动态页面的格式都是类似 pageName.aspx?ID=1的格式,后面由于发布服务器的原因,要求将动态页面转为静态html后上传. 首先根据页面生成的格式,枚举获取页面html: foreach ...

  3. FineUI按钮控件

    按钮的状态与大小 按钮有启用/禁用,按下/正常几种状态,对应的属性分别为Enabled.EnablePress.Pressed三个属性. 按钮有大中小三个尺寸,对应的属性为Size. 按钮上的图标 按 ...

  4. Arcgis Engine - 脱离ToolBarControl控件的命令和工具

    可以手动实现脱离ToolBarControl控件的命令和工具 //打开文件. private void file_tsmItem_Click(object sender, EventArgs e) { ...

  5. tomcat 支持https

    HTTP是平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全.为了保证 这些隐私数据能加密传输,于是网景公司设计了SSL(Se ...

  6. 创建存储过程和函数【weber出品必属精品】

    一.什么是存储过程和函数 1. 是被命名的pl/sql块 2. 被称之为pl/sql子程序 3. 与匿名块类似,有块结构: 声明部分是可选的(没有declare关键字) 必须有执行部分 可选的异常处理 ...

  7. 全世界最详细的图形化VMware中linux环境下oracle安装(二)【weber出品必属精品】

    <ORACLE 10.2.05版本的升级补丁安装> 首先我们解压 $ unzip p8202632_10205_LINUX.zip 解压后我们会发现多出了个文件夹,他是:Disk1,进入D ...

  8. 定义block块

    一: 工程图 二: 代码区 AppDelegate.h #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <U ...

  9. 兼容性之IOS下label 无法点击

    今天做移动端的页面时碰到一个稀奇的问题,那就是点击label无法选中与之相关的checkbox,下面是问题代码: <li class="list-item clearfix notif ...

  10. Asp.Net MVC3.0 Partial RenderPartial Action RenderAction 区别和用法

    本人写的博文不多,专业知识不强,以下纯属于个人笔记.如有不对,还请各路大拿,拍砖指导,谢谢! 区别: 1.Partial 与 RenderPartial 两个方法性质基本一样,只是把一个静态用户控件给 ...