2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) E.Passwords AC自动机+dp
题目链接:点这里
题意:
让你构造一个长度范围在[A,B]之间 字符串(大小写字母,数字),问你有多少种方案
需要满足条件一下:
1:构成串中至少包含一个数字,一个大写字母,一个小写字母;
2:不能包含给定的N个病毒串
3:遵循一堆映射规则
题解:
将病毒串建立AC自动机
设定dp[i][j] [0/1][0/1][0/1]:表示构造长度为i,在自动机上面的状态是j,分别是否含有数字,大写字母,小写字母的情况
你能转移的点就是 加上一个数字或者大小写字母,暴力转移DP就好了,方程复杂度:20*1000*8,转移复杂度:26+26+10
整体复杂度:20*1000*8*62+建立trie
#include<bits/stdc++.h>
using namespace std;
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 1e6+, M = 1e3+;
LL mod = ;
int nex[][],q[],fail[],cnt=,black[],head,tail;
int rea_ID(int ch) {
if(ch >= && ch < ) return ch;
if(ch == ) return 'o'-'a';
if(ch == ) return 'i'-'a';
if(ch == ) return 'e'-'a';
if(ch == ) return 's'-'a';
if(ch == ) return 't'-'a';
if(ch >= && ch <= ) return ;
if(ch > && ch <= )return ch - ;
}
int ID(char ch) {
return ch - 'a';
}
void insert(char *s) {
int now = , len = strlen(s);
for(int i = ; i < len; ++i) {
int index = ID(s[i]);
if(!nex[now][index])
nex[now][index] = ++cnt;
now = nex[now][index];
}
black[now] |= ;
}
void build_fail() {
head = , tail = ;
for(int i = ; i < ; ++i) nex[][i] = ;
fail[] = ;
q[tail++] = ;
while(head != tail) {
int now = q[head++];
black[now] |= black[fail[now]];
for(int i = ; i < ; ++i) {
int p = fail[now];
if(!nex[now][i]) {
nex[now][i] = nex[p][i];continue;
}
fail[nex[now][i]] = nex[p][i];
q[tail++] = nex[now][i];
}
nex[now][] = ;
}
}
int A,B,n;
char s[];
LL dp[][][][][];
int main()
{
scanf("%d%d",&A,&B);
scanf("%d",&n);
for(int i = ; i <= n; ++i) {
scanf("%s",s);
insert(s);
}
build_fail();
dp[][][][][] = ;
for(int i = ; i <= B; ++i) {
for(int j = ; j <= cnt; ++j) {
for(int dxziok = ; dxziok <= ; ++dxziok)
for(int shuziok = ; shuziok <= ; ++shuziok)
for(int xxziok = ; xxziok <= ; ++xxziok) {
if(dp[i][j][dxziok][shuziok][xxziok] == ) continue;
for(int k = ; k <= ; ++k) {
int rea = rea_ID(k);
int tmp1 = ,tmp2 = ,tmp3 = ;
if(k < ) tmp1 = ;
else if(k <= ) tmp2 = ;
else tmp3 = ;
if(!black[nex[j][rea]])
dp[i+][nex[j][rea]][dxziok|tmp1][shuziok|tmp2][xxziok|tmp3] +=
dp[i][j][dxziok][shuziok][xxziok];
dp[i+][nex[j][rea]][dxziok|tmp1][shuziok|tmp2][xxziok|tmp3]%=mod;
}
} }
}
LL ans = ;
for(int i = A; i <= B; ++i) {
for(int j = ; j <= cnt; ++j) {
ans = (ans + dp[i][j][][][])%mod;
}
}
cout<<ans<<endl;
return ;
}
2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) E.Passwords AC自动机+dp的更多相关文章
- Gym 2009-2010 ACM ICPC Southwestern European Regional Programming Contest (SWERC 2009) A. Trick or Treat (三分)
题意:在二维坐标轴上给你一堆点,在x轴上找一个点,使得该点到其他点的最大距离最小. 题解:随便找几个点画个图,不难发现,答案具有凹凸性,有极小值,所以我们直接三分来找即可. 代码: int n; lo ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) F dfs序+树状数组
Performance ReviewEmployee performance reviews are a necessary evil in any company. In a performance ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)
A. Within Arm's Reach 留坑. B. Bribing Eve 枚举经过$1$号点的所有直线,统计直线右侧的点数,旋转卡壳即可. 时间复杂度$O(n\log n)$. #includ ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) B - Bribing Eve
地址:http://codeforces.com/gym/101174/attachments 题目:pdf,略 思路: 把每个人的(x1,x2)抽象成点(xi,yi). 当1号比i号排名高时有==& ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) D.Dinner Bet 概率DP+排列组合
题目链接:点这里 题意: 1~N标号的球 现在A有C个,B有C个 每次可以随机得到D个不同的球(1~N);问你A或B中的C个球都出现一次的 期望次数 题解: dp[i][j][k]表示 随机出现了i个 ...
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)
A. Cakey McCakeFace 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string.h&g ...
- 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)
A. Arranging Hat $f[i][j]$表示保证前$i$个数字有序,修改了$j$次时第$i$个数字的最小值. 时间复杂度$O(n^3m)$. #include <bits/stdc+ ...
- 2016-2017 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2016)
题目链接 Codefores_Gym_101164 Solved 6/11 Penalty Problem A Problem B Problem C Problem D Problem E Pr ...
- 2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017)
2017-2018 ACM-ICPC Southeastern European Regional Programming Contest (SEERC 2017) 全靠 wxh的博客 补完这套.wx ...
随机推荐
- 生成 Let's Encrypt 免费https证书
1.打开 SSL For Free 官网:https://www.sslforfree.com/ 2.在输入框内输入你要申请证书的域名,输入完点击 Create Free SSL Certificat ...
- Python之阻塞IO模型与非阻塞IO模型
Python之阻塞IO模型与非阻塞IO模型 IO模型 1 阻塞IO: 全程阻塞 2 非阻塞IO: 发送多次系统调用: 优点:wait for data时无阻塞 缺点:1 系统调用太多 2 数据不是实时 ...
- 04 Beautiful Soup
Beautiful Soup 简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: ''' Beautiful Soup提供一些简单的.py ...
- 【java基础 3】树形结构数据呈现的递归算法实现
一.基本概况 在我的项目中,常常会用到树形结构的数据,最为明显的就是左边菜单栏,类似于window folder一样的东西. 而我之前一直是借助前端封装好的ZTree等工具实现展示,而后台则通常使用递 ...
- 虚拟机(Virtual Machine)和容器(Container)的对比
目前云计算平台常用的虚拟化技术有虚拟机(Virtual Machine)和容器(Container)两种.虚拟机已经是比较成熟的技术,容器技术作为下一代虚拟化技术,国内的各厂商应用还不广,但似乎其代表 ...
- Linux使用Mutt发送邮件/附件
使用Mutt发邮件极其方便,只需要一条命令即可发送或者批量发送邮件 功能说明:E-mail管理程序. 语 法:mutt [-hnpRvxz][-a<文件>][-b<地址>][- ...
- html template & import link bug
html template & import link bug html templates is OK https://caniuse.com/#search=html%20template ...
- 【尺取】HDU Problem Killer
acm.hdu.edu.cn/showproblem.php?pid=5328 [题意] 给定一个长度为n的正整数序列,选出一个连续子序列,这个子序列是等差数列或者等比数列,问这样的连续子序列最长是多 ...
- 海战(洛谷 P1331)
题目描述 在峰会期间,武装部队得处于高度戒备.警察将监视每一条大街,军队将保卫建筑物,领空将布满了F-2003飞机.此外,巡洋船只和舰队将被派去保护海岸线.不幸的是因为种种原因,国防海军部仅有很少的几 ...
- MySql基本数据类型(转)
说明:通俗的理解:1字节的8位,即1byte=8bit,而这个1byte叫做长度范围,范围的算法是使用bit去求,比如8bit的长度范围是2的8次方,但是在数据库中的类型上是有区分有符号和无符号的,默 ...