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 ...
随机推荐
- 如何在Python中显式释放内存?
根据Python官方文档,您可以强制垃圾收集器释放未引用的内存gc.collect().例: import gc gc.collect() 所属网站分类: python高级 > 综合&其 ...
- Python爬虫-爬取京东商品信息-按给定关键词
目的:按给定关键词爬取京东商品信息,并保存至mongodb. 字段:title.url.store.store_url.item_id.price.comments_count.comments 工具 ...
- scrapy之自定制命令
写好自己的爬虫项目之后,可以自己定制爬虫运行的命令. 一.单爬虫 在项目的根目录下新建一个py文件,如命名为start.py,写入如下代码: from scrapy.cmdline import ex ...
- AI学习笔记(01)
[1]在Ai中,每个对象有两个属性:填充颜色和描边颜色. [2]在AI中,非要选中,才操作.而PS中,选中图层即可. [3]AI中,都是路径. [4]选择工具是选中整个路径,而直接选择工具 ...
- 【最小费用最大流】N. April Fools' Problem (medium)
http://codeforces.com/contest/802/problem/N [题解] 方法一: #include<bits/stdc++.h> using namespace ...
- eclipse pom.xml 报错org.apache.maven.plugin.war.WarMojo的解决办法
如题,maven项目eclipse提示pom.ml有错,提示信息就是org.apache.maven.plugin.war.WarMojo. 然后执行 maven install 出现如下错误提示 [ ...
- 【SPOJ694&705】Distinct Substrings(后缀数组)
题意:求一个字符串的不相同的子串个数 n<=1000 思路:这是一道论文题 ..]of longint; n,i,m,ans,v,cas:longint; ch:ansistring; proc ...
- MySQL介绍及安装&MySQL软件基本管理
mysql介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好 ...
- Django学习之 - 基础部分
学习记录参考: 讲师博客:http://www.cnblogs.com/wupeiqi/articles/5433893.html 老男孩博客:http://oldboy.blog.51cto.com ...
- express 写接口
实例下载:百度云盘免密码 (): 指注释 一.准备工作 1.安装express npm install express -g npm install express-generator -g 2.初始 ...