hdu2825 Wireless Password(AC自动机+状压dp)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5400 Accepted Submission(s): 1704
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.
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.
hello
world
4 1 1
icpc
10 0 0
0 0 0
1
14195065
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define pi acos(-1.0)
#define maxn 505
#define maxnode 205
#define MOD 20090717
int dp[30][105][1050];
struct trie{
int sz,root,val[maxnode],next[maxnode][30],fail[maxnode];
int q[1111111];
void init(){
int i;
sz=root=0;
val[0]=0;
for(i=0;i<26;i++){
next[root][i]=-1;
}
}
int idx(char c){
return c-'a';
}
void charu(char *s,int index){
int i,j,u=0;
int len=strlen(s);
for(i=0;i<len;i++){
int c=idx(s[i]);
if(next[u][c]==-1){
sz++;
val[sz]=0;
next[u][c]=sz;
u=next[u][c];
for(j=0;j<26;j++){
next[u][j]=-1;
}
}
else{
u=next[u][c];
}
}
val[u]|=(1<<index-1);
}
void build(){
int i,j;
int front,rear;
front=1;rear=0;
for(i=0;i<26;i++){
if(next[root][i]==-1 ){
next[root][i]=root;
}
else{
fail[next[root][i] ]=root;
rear++;
q[rear]=next[root][i];
}
}
while(front<=rear){
int x=q[front];
val[x]|=val[fail[x] ];
front++;
for(i=0;i<26;i++){
if(next[x][i]==-1){
next[x][i]=next[fail[x] ][i];
}
else{
fail[next[x][i] ]=next[fail[x] ][i];
rear++;
q[rear]=next[x][i];
}
}
}
}
}ac;
int panduan(int state,int k){
int i,j,num;
num=0;
while(state){
if(state%2==1)num++;
state>>=1;
}
if(num>=k)return 1;
return 0;
}
int main()
{
int n,m,i,j,k,state,state1,ii,jj,t;
char s[20];
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
if(n==0 && m==0 && k==0)break;
ac.init();
for(i=1;i<=m;i++){
scanf("%s",s);
ac.charu(s,i);
}
ac.build();
memset(dp,0,sizeof(dp));
dp[0][0][0]=1;
for(i=0;i<=n-1;i++){
for(j=0;j<=ac.sz;j++){
for(state=0;state<=((1<<m)-1);state++ ){
if(dp[i][j][state]){
for(t=0;t<26;t++){
int ii=i+1;
int jj=ac.next[j][t];
int state1=(state| ac.val[ac.next[j][t] ] );
dp[ii][jj][state1]=(dp[ii][jj][state1]+dp[i][j][state])%MOD;
}
}
}
}
}
int sum=0;
for(state=0;state<=((1<<m)-1);state++){
if(panduan(state,k)){
for(j=0;j<=ac.sz;j++){
sum+=dp[n][j][state];
sum%=MOD;
}
}
}
printf("%d\n",sum);
}
return 0;
}
hdu2825 Wireless Password(AC自动机+状压dp)的更多相关文章
- HDU2825 Wireless Password —— AC自动机 + 状压DP
题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others) ...
- HDU-2825 Wireless Password(AC自动机+状压DP)
题目大意:给一系列字符串,用小写字母构造出长度为n的至少包含k个字符串的字符串,求能构造出的个数. 题目分析:在AC自动机上走n步,至少经过k个单词节点,求有多少种走法. 代码如下: # includ ...
- 【HDU2825】Wireless Password (AC自动机+状压DP)
Wireless Password Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u De ...
- hdu_2825_Wireless Password(AC自动机+状压DP)
题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- BZOJ1559 [JSOI2009]密码 【AC自动机 + 状压dp】
题目链接 BZOJ1559 题解 考虑到这是一个包含子串的问题,而且子串非常少,我们考虑\(AC\)自动机上的状压\(dp\) 设\(f[i][j][s]\)表示长度为\(i\)的串,匹配到了\(AC ...
- HDU 3247 Resource Archiver(AC自动机 + 状压DP + bfs预处理)题解
题意:目标串n( <= 10)个,病毒串m( < 1000)个,问包含所有目标串无病毒串的最小长度 思路:貌似是个简单的状压DP + AC自动机,但是发现dp[1 << n][ ...
- zoj3545Rescue the Rabbit (AC自动机+状压dp+滚动数组)
Time Limit: 10 Seconds Memory Limit: 65536 KB Dr. X is a biologist, who likes rabbits very much ...
- hdu 4057--Rescue the Rabbit(AC自动机+状压DP)
题目链接 Problem Description Dr. X is a biologist, who likes rabbits very much and can do everything for ...
随机推荐
- mysql .sock丢时候如何链接数据库
在mysql服务器本机上链接mysql数据库时,经常会噢出现mysql.sock不存在,导致无法链接的问题,这是因为如果指定localhost作为一个主机名,则mysqladmin默认使用unix套接 ...
- 使用yaml配置文件管理资源
[root@k8s-master ~]# vim nginx-deployment.yaml apiVersion: apps/v1beta2 kind: Deployment metadata: n ...
- oralce move和shrink释放高水位
转自:https://blog.51cto.com/fengfeng688/1955137 move和shrink的共同点: 收缩段,消除部分行迁移,消除空间碎片,使数据更紧密 shrink用法: 语 ...
- Git 沙盒模拟实战(远程篇)
Git 沙盒模拟实战(远程篇) >---基础篇 远程仓库 远程仓库并不复杂, 在如今的云计算盛行的世界很容易把远程仓库想象成一个富有魔力的东西, 但实际上它们只是你的仓库在另个一台计算机上的拷贝 ...
- Kubernetes 开船记-脚踏两只船:用 master 服务器镜像克隆出新集群
自从2020年2月23日 园子全站登船 之后,我们一边感叹"不上船不知道,一上船吓一跳" -- kubernetes 比 docker swarm 强大太多,一边有一个杞人忧天的担 ...
- 视图V_160M和表T_160M的维护
今天发现一个视图,通过SM30居然无法维护,这个视图就是V_160M,表为T_160M,是采购相关的系统消息, 不过别着急,有办法维护的,呵呵,看下面: 试一试OMCQ这个事物代码吧! 分享出来,给需 ...
- linux中的虚拟环境工具
1.虚拟环境工具的学习 python的虚拟环境,其实就是在机器上,方便的创建出多个解释器,每个解释器运行一个项目,互相之间不受影响 2.virtualenv工具,可以方便的创建,使用,删除也很方便 3 ...
- pytorch——合并分割
分割与合并 import torch import numpy as np #假设a是班级1-4的数据,每个班级里有32个学生,每个学生有8门分数 #假设b是班级5-9的数据,每个班级里有32个学生, ...
- Py其他内置函数,文件修改
其他内置函数 1.abs函数,取绝对值 print(abs(-1)) 2.all函数,判断可迭代对象是否全为真,有假直接假 假:0,'',None print(all([1,2,'1'])) prin ...
- Python+Selenium+Unittest实现PO模式web自动化框架(1)
1.什么是PO模式? PO是Page Object的缩写 PO模式是自动化测试项目开发实践的最佳设计模式之一,讲页面定位和业务操作分开,也就是把对象的定位和测试脚本分开,从而提供可维护性. 主要有以下 ...