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的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. CSS Vocabulary – CSS 词汇表,你都掌握了吗?

    CSS 是前端开发必备技能,入门容易,深入难.比如像 Pseudo-class.Pseudo-element.Media query.Media type 以及 Vendor prefix 的概念,很 ...

  3. [BEC][hujiang] Lesson03 Unit1:Working life ---Grammar & Listening & Vocabulary

    3 Working life p8 Grammar Gerund and infinitive(动名词和不定式) 一般而言:        1 动词后面接动名词还是不定式没有特定规则,主要取决于语言习 ...

  4. Vocabulary & Phrase

    Vocabulary A ANSI    美国国家标准学会,American National Standards Institute的缩写 a couple of    [口语]少数的,几个 a s ...

  5. Duplicate column name 'vocabulary'

    创建一个视图: 报错:Duplicate column name 'vocabulary' 意思是视图select的列名重复了,取别名 改成这样就ok了

  6. 11. English vocabulary 英语词汇量

    11. English vocabulary 英语词汇量 (1) The exact number of English words is not known.The large dictionari ...

  7. Easy-to-Learn English Travel Phrases and Vocabulary!

    Easy-to-Learn English Travel Phrases and Vocabulary! Share Tweet Share Tagged With: Real Life Englis ...

  8. American Football Vocabulary!

    American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...

  9. bzoj千题计划234:bzoj3802: Vocabulary

    http://www.lydsy.com/JudgeOnline/problem.php?id=3802 dp[i][0/1/2/3]  表示前i个字母,第1.2个字符串,第2.3个字符串的关系分别为 ...

随机推荐

  1. http://www.16aspx.com/Code/Show/5352

    http://www.16aspx.com/Code/Show/5352 可视化工作流引擎RoadFlowV1.3 http://www.cnblogs.com/f2flow/p/4212678.ht ...

  2. simple-todo: 一个简易的 todo 程序 - django版

    今天无意间看到  simple-todo: 一个简易的 todo 程序 - web.py 中文教程 ,然后发现竟然有好多的版本 http://simple-is-better.com/news/tag ...

  3. Windows7系统下优化固态硬盘

    一.AHCI硬盘模式可提高硬盘性能,确定你的固态硬盘是运行在AHCI模式下,打开“HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servicesmsahci” ...

  4. 战五渣系列之八(绝杀AOP)

    开发不用aop.程序猿的人生该会浪费多少时间.我想是时候让程序猿打败alpha狗了.程序猿解救世界. 1.概念 面向切面编程.这意味着,一切不在流水线上的东西.包含权限.日志.缓存.校验.资源.事物. ...

  5. 基于Spring-SpringMVC-Mybatis的简单样例

    复习下 好久没搞过撸过代码了! 这个样例包括一个完整的增删改查! 源代码地址http://download.csdn.net/detail/wangdianyong/8909903

  6. poj 2585 Window Pains 暴力枚举排列

    题意: 在4*4的格子中有9个窗体,窗体会覆盖它之下的窗体,问是否存在一个窗体放置的顺序使得最后的结果与输入同样. 分析: 在数据规模较小且不须要剪枝的情况下能够暴力(思路清晰代码简单),暴力一般分为 ...

  7. Lnixu Bash

    一.简单命令 1.创建文件(vi) vi hellowold.txt2.创建目录(mkdir) mkdir linux_bash3.删除文件(rm) rm helloworld.txt4.复制文件(c ...

  8. Python安装Mysql驱动出错解决(最新出炉)

    Python中最连接Mysql常用的驱动是 mysql-python :mysql的C语言的驱动 mysql-connector:msql官方的驱动 pymysql:python语言的驱动 我这里安装 ...

  9. C++ 虚函数与纯虚函数 浅析

    [摘要] 在虚函数与纯虚函数的学习中.要求理解虚函数与纯虚函数的定义,了解虚函数与纯虚函数在实例化上的差异.掌握两者在实现上的必要性.熟悉纯虚函数在子类与孙类的函数类型.本文即针对上述问题展开阐述. ...

  10. Delphi汉字简繁体转换代码(分为D7和D2010版本)

    //delphi 7 Delphi汉字简繁体转换代码unit ChineseCharactersConvert; interface uses   Classes, Windows; type   T ...