[BZOJ4043/CERC2014]Vocabulary
Description
给你三个字符串,这些字符串有些单词模糊不可认了,用"?"来代表。
现在你可以用任意英文小写字母来代表它们。要求是使得给定的三个字符串中
所有的"?"被你认定的字母代替后,各不相同且按字典序出现。问有多少种方式。
Input
先给出一个数字N,代表数据组数。
接下来3*N行,每行给出一个字符串。长度<=1000 000
Output
输出结果 Mod 10^9+9
Sample Input
3
?heoret?cal
c?mputer
?cience
jagiellonia
?niversity
kra?ow
?
b
c
Sample Output
42562
52
1
我们令三个字符串为A,B,C,设\(f[i][0/1/2/3]\)表示当前扫到第i个字符串,0表示A=B=C,1表示A=B<C,2表示A<B=C,3表示A<B<C的方案数,但是这样转移需要枚举当前填的字符和上一个填的字符,复杂度太高
所以我们可以预处理出\(g[x][y][i][j][k]\),表示当前字符为i,j,k,状态由x转移到y的方案数,然后就可以大力转移f了
/*problem from Wolfycz*/
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-');
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e6,p=1e9+9;
int g[5][5][30][30][30];
void prepare(){
for (int i=0;i<=27;i++){
for (int j=0;j<=27;j++){
for (int k=0;k<=27;k++){
int li=(i==27)?1:i,ri=(i==27)?26:i;
for (int x=li;x<=ri;x++){
int lj=(j==27)?1:j,rj=(j==27)?26:j;
for (int y=lj;y<=rj;y++){
int lk=(k==27)?1:k,rk=(k==27)?26:k;
for (int z=lk;z<=rk;z++){
if (x==y&&y==z) g[0][0][i][j][k]++;
if (x==y&&y< z) g[0][1][i][j][k]++;
if (x< y&&y==z) g[0][2][i][j][k]++;
if (x< y&&y< z) g[0][3][i][j][k]++;
if (x==y) g[1][1][i][j][k]++;
if (y==z) g[2][2][i][j][k]++;
if (x< y) g[1][3][i][j][k]++;
if (y< z) g[2][3][i][j][k]++;
g[3][3][i][j][k]++;
}
}
}
}
}
}
}
char s[N+10];
int v[5][N+10];
int f[5][N+10];
void init(int &len,int *a){
scanf("%s",s+1);
len=strlen(s+1);
for (int i=1;i<=len;i++) a[i]=(s[i]=='?'?27:s[i]-'a'+1);
}
int main(){
prepare();
for (int Data=read();Data;Data--){
int n1,n2,n3,len;
init(n1,v[1]),init(n2,v[2]),init(n3,v[3]);
len=max(max(n1,n2),n3);
for (int i=n1+1;i<=len;i++) v[1][i]=0;
for (int i=n2+1;i<=len;i++) v[2][i]=0;
for (int i=n3+1;i<=len;i++) v[3][i]=0;
f[0][0]=1;
for (int i=1;i<=len;i++){
for (int j=0;j<4;j++) f[j][i]=0;
for (int j=0;j<4;j++)
for (int k=0;k<4;k++)
f[j][i]=(f[j][i]+1ll*f[k][i-1]*g[k][j][v[1][i]][v[2][i]][v[3][i]]%p)%p;
}
printf("%d\n",f[3][len]);
}
return 0;
}
[BZOJ4043/CERC2014]Vocabulary的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- CSS Vocabulary – CSS 词汇表,你都掌握了吗?
CSS 是前端开发必备技能,入门容易,深入难.比如像 Pseudo-class.Pseudo-element.Media query.Media type 以及 Vendor prefix 的概念,很 ...
- [BEC][hujiang] Lesson03 Unit1:Working life ---Grammar & Listening & Vocabulary
3 Working life p8 Grammar Gerund and infinitive(动名词和不定式) 一般而言: 1 动词后面接动名词还是不定式没有特定规则,主要取决于语言习 ...
- Vocabulary & Phrase
Vocabulary A ANSI 美国国家标准学会,American National Standards Institute的缩写 a couple of [口语]少数的,几个 a s ...
- Duplicate column name 'vocabulary'
创建一个视图: 报错:Duplicate column name 'vocabulary' 意思是视图select的列名重复了,取别名 改成这样就ok了
- 11. English vocabulary 英语词汇量
11. English vocabulary 英语词汇量 (1) The exact number of English words is not known.The large dictionari ...
- Easy-to-Learn English Travel Phrases and Vocabulary!
Easy-to-Learn English Travel Phrases and Vocabulary! Share Tweet Share Tagged With: Real Life Englis ...
- American Football Vocabulary!
American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...
- bzoj千题计划234:bzoj3802: Vocabulary
http://www.lydsy.com/JudgeOnline/problem.php?id=3802 dp[i][0/1/2/3] 表示前i个字母,第1.2个字符串,第2.3个字符串的关系分别为 ...
随机推荐
- 个人网站开发***云服务器+Linux+域名***
作为一个改变世界的程序猿,我们不应该只会埋头写程序修bug还得会点别的, 当然如果要是自己搞个网站玩玩,既可以锻炼技术,没事也可以和圈外的朋友吹吹 牛.因为水平有限,就弄一些最基础的看看喽,不喜勿喷. ...
- 奥斯卡·王尔德十大经典语录
10不够真诚是危急的,太真诚则绝对是致命的.--摘自<身为艺术家的评论者> "A little sincerity is a dangerous thing, and a gre ...
- 转帖:对linux中半增加半连接数量和防止服务器被dos攻击
.增大队列SYN最大半连接数 在Linux中执行命令"sysctl -a|grep net.ipv4.tcp_max_syn_backlog",在返回的"net.ipv4 ...
- 2016/2/26 <marquee></marquee>实现多种滚动效果
页面的自动滚动效果,可由javascript来实现,但是有一个html标签 - <marquee></marquee>可以实现多种滚动效果,无需js控制.使用marquee标记 ...
- myeclipse包的层数和package的层数不一致
复制别人的工程的时候常常遇到包的层数不一致的情况 如下图 其实com.weibo.happpy.dao的上面还有一层java包,但是代码里没有写java....... 可以通过如下方式修改工程:
- Interpret bytes as packed binary data
7.1. struct — Interpret bytes as packed binary data — Python 3.6.5 documentation https://docs.python ...
- eclipse 重启/打开内置浏览器
重启 Eclipse 重启选项允许用户重启 Eclipse. 我们可以通过点击 File 菜单选择 Restart 菜单项来重启 Eclipse. Eclipse 内置浏览器 Web 浏览器 Ecli ...
- ATan2与ATan的区别
相比较ATan,ATan2究竟有什么不同?本篇介绍一下ATan2的用法及使用条件. 对于tan(θ) = y / x: θ = ATan(y / x)求出的θ取值范围是[-PI/2, PI/2]. θ ...
- YTU 2412: 帮警长数一数【循环、分支简单综合】
2412: 帮警长数一数[循环.分支简单综合] 时间限制: 1 Sec 内存限制: 64 MB 提交: 323 解决: 169 题目描述 黑猫警长在犯罪现场发现了一些血迹,现已经委托检验机构确定了 ...
- YTU 2574: 空白格式化
2574: 空白格式化 时间限制: 1 Sec 内存限制: 128 MB 提交: 233 解决: 118 题目描述 恭喜你进入了蓝桥杯总决赛,本次大赛采用了全自动机器测评系统. 如果你的答案与标准 ...