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. Java的基本运算符

    以下内容引用自http://wiki.jikexueyuan.com/project/java/basic-operators.html: Java针对操控变量提供了一组丰富的运算符.可以将所有的Ja ...

  2. c++之虚基类初始化

    C++虚基类构造函数下面文章详细介绍C++虚基,所谓C++虚基类:是由最派生类的构造函数通过调用虚基类的构造函数进行初始化的,但前提是要深入理解到底什么是C++虚基类,及他是怎么运行的. 前面讲过,为 ...

  3. uva 10069 Distinct Subsequences 【dp+大数】

    题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...

  4. Intellij IDEA远程调试tomcat

    1.windows系统 文件catalina.bat首行增加下面代码 set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE ...

  5. Android Studio一些简单设置

          简单设置   1.默认主题设置 默认的 Android Studio 为灰色界面,能够选择使用炫酷的黑色界面. Settings --> Appearance --> Them ...

  6. #define中的#和##作用

    #define语句中的#是把参数字符串化,##是连接两个参数成为一个整体. #define FACTORY_REF(name) { #name, Make##name } 中#name就是将传入的na ...

  7. Android数据与服务器交互的GET,POST,HTTPGET,HTTPPOST的使用

    Android有这几种方式,可以提交数据到服务器,他们是怎么使用的呢,这里我们来探讨一下. 这里的例子用的都是提交客户端的用户名及密码,同时本节用到的StreamTools.readInputStre ...

  8. 用UltraEdit比較两个文件

    在编写代码的过程中,经常碰到两个文件之间的逐行比較.特别是新代码与源码之间的文字比較,这里介绍用UltraEdit实现新代码与源码之间的比較方法. //源码:Bearing.mac FINISH /C ...

  9. 2016/2/26 jQuery的技术 1,安装 2,语法选择器$ 事件触发 3,常用jQuery函数

    在<网页制作Dreamweaver(悬浮动态分层导航)>中,运用到了jQuery的技术,轻松实现了菜单的下拉.显示.隐藏的效果,不必再用样式表一点点地修改,省去了很多麻烦,那么jQuery ...

  10. [NOIP2012] day2 T3疫情控制

    题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都,也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控制疫情,不让疫情扩散到 ...