HDU - 2825 Wireless Password (AC自动机+状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2825
题意:给一些字符串,构造出长度为n的字符串,它至少包含k个所给字符串,求能构造出的个数。
题解:
对end[]节点标记数组进行改动,用二进制下第几位表示即为包含第几个给定子串;
状态转移方程为:dp[i+1][x][k|end[x]]=(dp[i+1][x][k|end[x]]+dp[i][j][k])%mod;(没懂为什么要用‘ | ’ ,等搞明白了在更新吧,,)
dp[i][j][l] 表示长度 i 在第j个结点且当前包含字符串集合为 l 的方案数;
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 const ll mod=20090717;
6 const ll maxn = 111;
7 ll ans=0;
8 ll sum[1100];
9 ll n,m,k;
10
11 struct tire{
12 ll nxt[maxn][30],fail[maxn],end[maxn],tot,root,vis[maxn];
13 ll newNode(){
14 for(ll i=0;i<26;i++) nxt[tot][i] = -1;
15 end[tot++] = 0;
16 return tot-1;
17 }
18 void Init(){
19 tot = 0;
20 root = newNode();
21 memset(dp,0,sizeof(dp));
22 }
23 void Insert(char *buf,ll id){
24 ll len = strlen(buf),i,u = root;
25 for(i=0;i<len;i++){
26 ll x = buf[i]-'a';
27 if(nxt[u][x]==-1) nxt[u][x] = newNode();
28 u = nxt[u][x];
29 }
30 end[u] |= 1<<id;
31 }
32 void build(){
33 queue <ll> q;
34 fail[root] = root;
35 for(ll i=0;i<26;i++){
36 if(nxt[root][i]==-1) nxt[root][i] = root;
37 else{
38 fail[nxt[root][i]] = root;
39 q.push(nxt[root][i]);
40 }
41 }
42 while(!q.empty()){
43 ll now = q.front();
44 q.pop();
45 for(ll i=0;i<26;i++){
46 if(nxt[now][i]==-1) nxt[now][i] = nxt[fail[now]][i];
47 else{
48 fail[nxt[now][i]] = nxt[fail[now]][i];
49 q.push(nxt[now][i]);
50 }
51 }
52 end[now]|=end[fail[now]];
53 }
54 }
55 ll dp[30][111][1<<10];
56 void solve(){
57 dp[0][0][0]=1;
58 for(ll i=0;i<n;i++){
59 for(ll j=0;j<tot;j++){
60 for(ll k=0;k<(1<<m);k++){
61 if(dp[i][j][k]){
62 for(ll u=0;u<26;u++){
63 ll x=nxt[j][u];
64 dp[i+1][x][k|end[x]]+=dp[i][j][k];
65 dp[i+1][x][k|end[x]]%=mod;
66 }
67 }
68 }
69 }
70 }
71 ans=0;
72 for(ll i=0;i<tot;i++){
73 for(ll j=0;j<(1<<m);j++){
74 if(dp[n][i][j]&&sum[j]>=k) ans=(ans+dp[n][i][j])%mod;
75 }
76 }
77 cout<<ans<<endl;
78 }
79 }ac;
80
81 char s1[maxn];
82
83 int main()
84 {
85 for(ll i=0;i<(1<<10);i++){
86 for(ll j=0;j<10;j++){
87 if(i&(1<<j)) sum[i]++;
88 }
89 }
90 while(cin>>n>>m>>k){
91 if(!n&&!m&&!k) break;
92 ac.Init();
93 for(ll i=0;i<m;i++){
94 cin>>s1;
95 ac.Insert(s1,i);
96 }
97 ac.build();
98 ac.solve();
99 }
100 return 0;
101 }
HDU - 2825 Wireless Password (AC自动机+状压DP)的更多相关文章
- hdu2825 Wireless Password(AC自动机+状压dp)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission ...
- 【HDU2825】Wireless Password (AC自动机+状压DP)
Wireless Password Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u De ...
- 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 ...
- hdu 4057--Rescue the Rabbit(AC自动机+状压DP)
题目链接 Problem Description Dr. X is a biologist, who likes rabbits very much and can do everything for ...
- hdu_2825_Wireless Password(AC自动机+状压DP)
题目链接:hdu_2825_Wireless Password 题意: 给你m个串,问长度为n至少含k个串的字符串有多少个 题解: 设dp[i][j][k]表示考虑到长度为i,第j个自动机的节点,含有 ...
- HDU 2825 Wireless Password(AC自动机+DP)
题目链接 做题, #include <cstdio> #include <string> #include <cstring> using namespace st ...
- HDU - 2825 Wireless Password(AC自己主动机+DP)
Description Liyuan lives in a old apartment. One day, he suddenly found that there was a wireless ne ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 2825 Wireless Password (AC自己主动机,DP)
pid=2825">http://acm.hdu.edu.cn/showproblem.php? pid=2825 Wireless Password Time Limit: 2000 ...
随机推荐
- LInux维护一:VirtualMachine磁盘扩容
- 【JDBC核心】commons-dbutils
commons-dbutils 简介 commons-dbutils 是 Apache 组织提供的一个开源 JDBC 工具类库,它是对 JDBC 的简单封装,学习成本极低,并且使用 commons-d ...
- AttGAN: Facial Attribute Editing by Only Changing What You Want 论文阅读笔记和AttGan的pytorch代码实现
1.总体框架 上面的过程用详细描述即是 Test阶段: Train阶段: 由于我们无法得知编辑后的image,所以显而易见人脸属性编辑是一个无监督问题,而对于我们的xa需要获得关于b的属性,故利用at ...
- linux命名小技巧(持续更新)
一 向某个文件批量加入内容 1.1 向/etc/wxm文件添加一大段内容可以使用这个命令 [root@registry easyrsa3]# cat <<EOF >varsset ...
- 利用iptables防火墙保护web服务器
实例:利用iptables防火墙保护web服务器 防火墙--->路由器-->交换机-->pc机 配置之前,清空下已有的规则,放在规则冲突不生效 工作中,先放行端口写完规则,再DROP ...
- (四)React Ant Design Pro + .Net5 WebApi:PostgreSQL数据库环境搭建
一.简介 PostgreSQL,开源数据库(没听过小伙伴自己反思一下自行百度) PgAdmin,官方提供的数据库管理工具. 二.环境 1. 官网下载包,安装数据库 tar xjvf /app/pack ...
- SAP表的锁定与解锁
表的锁定模式有三种模式. lock mode有三种模式:分别是S,E,X.含义如下: S (Shared lock, read lock) E (Exclusive lock, wri ...
- Centos7.4 小白式安装(初学)
虚拟机安装Centos7.4系统 适用人群(初学者) 下载Centos7.4镜像 https://pan.baidu.com/s/1NtjfdHV3OWAvfDj5vrR7HQ 提取码:hzzw 虚 ...
- 一文告诉你Java日期时间API到底有多烂
前言 你好,我是A哥(YourBatman). 好看的代码,千篇一律!难看的代码,卧槽卧槽~其实没有什么代码是"史上最烂"的,要有也只有"史上更烂". 日期是商 ...
- spring源码分析之玩转ioc:bean初始化和依赖注入(一)
最近赶项目,天天加班到十一二点,终于把文档和代码都整完了,接上继续整. 上一篇聊了beanProcess的注册以及对bean的自定义修改和添加,也标志着创建bean的准备工作都做好了,接下来就是开大招 ...