bzoj3802: Vocabulary
Description
Input
Output
输出结果 Mod 10^9+9
在末尾补0直到三个串等长,dp一下,状态表示为当前考虑了前i个位置,三个串的大小关系(1=2=3,1<2=3,1=2<3,1<2<3),预处理一下每种情况的状态转移矩阵(但矩阵乘法复杂度不优,因此直接计算)
#include<cstdio>
#include<cstring>
typedef long long i64;
const int P=1e9+;
int T,l[],ml,t[][][][][],ls[],rs[];
int f[],g[];
char s[][];
void maxs(int&a,int b){if(a<b)a=b;}
int sgn(int a,int b){return +(a>b)-(a<b);}
#define F(i,n) for(int i=0;i<n;++i)
int main(){
for(int i=;i<;++i)ls[i]=rs[i]=i;
ls[]=;rs[]=;
F(i,)F(j,)F(k,){
int(*A)[]=t[i][j][k];
for(int a=ls[i];a<=rs[i];++a)
for(int b=ls[j];b<=rs[j];++b)
for(int c=ls[k];c<=rs[k];++c){
int xx=sgn(a,b),yy=sgn(b,c);
F(x,)F(y,){
int x1=(x?xx:),y1=(y?yy:);
if(x1<&&y1<)++A[x1*+y1][x*+y];
}
}
}
for(scanf("%d",&T);T;--T){
ml=;
F(i,){
scanf("%s",s[i]);
l[i]=strlen(s[i]);
maxs(ml,l[i]);
}
F(i,){
F(j,l[i])s[i][j]=s[i][j]=='?'?:s[i][j]-'a'+;
for(int j=l[i];j<ml;++j)s[i][j]=;
}
F(a,)f[a]=g[a]=;
f[]=;
F(i,ml){
F(a,)g[a]=;
int(*A)[]=t[s[][i]][s[][i]][s[][i]];
F(a,)F(b,){
g[a]=(g[a]+i64(f[b])*A[a][b])%P;
}
F(a,)f[a]=g[a];
}
printf("%d\n",(f[]+P)%P);
}
return ;
}
bzoj3802: Vocabulary的更多相关文章
- bzoj千题计划234:bzoj3802: Vocabulary
http://www.lydsy.com/JudgeOnline/problem.php?id=3802 dp[i][0/1/2/3] 表示前i个字母,第1.2个字符串,第2.3个字符串的关系分别为 ...
- 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 ...
- week 4 Vocabulary in paper
1.Using action verbs 1.1 deffenence between action verbs and fuzzy verbs Action verbs(strong verbs) ...
随机推荐
- Vue+Webpack配置css-loader时报错:Module build failed: Unknown word
使用Vue+Webpack搭建工程时,在webpack.config.js中的module的rules里针对各种文件配置加载工具.在针对css文件配置时遇到一个问题:打包构建时报错——Module b ...
- Flask 6 模板2
NOTE Jinja2提供了多种控制程序,可以用来改变模板的渲染流程. 1.在模板中使用条件控制语句: templates/condition.html: {% if user %} Hello, { ...
- java set初始化问题
set在执行add方法时,多次报空指针异常,后来发现Set初始化时,如果是 Set<Type> set = null; 这样的话,在执行 set.add(element)的时候会报空指针异 ...
- HDU 1969 精度二分
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- oracle性能诊断艺术-执行计划
--case1 --case2 --case3 --case4 --case5 --case6 --case7 --case8 --case9 --case10 --case12 SQL> AL ...
- oracle用户 密码永不过期
ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
- New Concept English Two 10 25
$课文23 新居 219. I had a letter from my sister yesterday. 昨天我收到了姐姐的一封信, 220. She lives in Nigeria. 她住在尼 ...
- linux 模拟生成 CAN 设备
/************************************************************************************** * linux 模拟生成 ...
- HDU1300 Pearls(可斜率优化)
+)*= +)*= .总共需要的花费是150+=++)*= .在两组数据看来.珍珠都买了高品质的了,而且花费也少了!问题是怎么样能花费最少买珍珠! Add:合并肯定是相邻的合并.比如啊a<b&l ...
- 6-18 Two Stacks In One Array(20 分)
Write routines to implement two stacks using only one array. Your stack routines should not declare ...