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. 【转】AOP

    原文:http://blog.csdn.net/zhoudaxia/article/details/38502347 .---------------------------------------- ...

  2. 设计模式之解释器模式(Interpreter)摘录

    23种GOF设计模式一般分为三大类:创建型模式.结构型模式.行为模式. 创建型模式抽象了实例化过程,它们帮助一个系统独立于怎样创建.组合和表示它的那些对象.一个类创建型模式使用继承改变被实例化的类,而 ...

  3. Python中的列表,元组,字符串之间的相互转化

    Python中的列表元组和字符串之间的相互转化需要利用,tuple(),list(),str(). 示例如下: >>> the_string = "hello I'am x ...

  4. pycharm快捷键和一些常用的设置

    http://blog.csdn.net/pipisorry/article/details/39909057 在PyCharm /opt/pycharm-3.4.1/help目录下可以找到Refer ...

  5. LoadRunner系列之—-03 用Java Vuser协议编写接口测试脚本

    待测试接口用java语言实现,且项目中调用该接口需要用专门的jar包.这种情况可以用Java Vuser协议实现接口调用脚本,类似java代码. 代码样例如下: /* * LoadRunner Jav ...

  6. ubuntu 安装后要做的事情

    1. 安装chrome,软件中心就可以. 2. 安装vim 和一些插件.这里引入一大牛配置的插件集 sudo apt-get install vim-gtk wget -qO- https://raw ...

  7. 浅谈asp.net通过本机cookie仿百度(google)实现搜索input框自己主动弹出搜索提示

    对于通过用户输入关键词实现自己主动弹出相关搜索结果,这里本人给两种解决方式,用于两种不同的情形. 常见方法是在数据库里建一个用户搜索关系表,然后通过用户搜索框输入的keyword异步调用数据表中的相关 ...

  8. 书评第003篇:《0day安全:软件漏洞分析技术(第2版)》

    本书基本信息 丛书名:安全技术大系 作者:王清(主编),张东辉.周浩.王继刚.赵双(编著) 出版社:电子工业出版社 出版时间:2011-6-1 ISBN:9787121133961 版次:1 页数:7 ...

  9. Linux(Ubuntu14.04)下Google Chrome / Chromium标题栏乱码问题

    注:我使用的Linux发行版是Ubuntu 14.04,不同Linux发行版可能会有不同. 最近在使用Chromium的时候tab的标题栏中文显示乱码,在地址栏输入中文是同样时乱码,就像下图: 看起来 ...

  10. poj1840Eqs(哈希判重)

    题目链接: 传送门 思路: 这道题是一个简单的hash的应用,假设直接暴力的话肯定承受不了5重for循环,所以比赛的时候我先到分成两组.可是后来用到了很多数组,然后想到数字太大,还先到stl判重, 后 ...