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) ...
随机推荐
- Java8 Lambda
Demo: package com.qhong; public class Main { public static void main(String[] args) throws Exception ...
- Firefox管理已经保存的账号和密码
https://support.mozilla.org/en-US/kb/password-manager-remember-delete-change-and-import You can easi ...
- python 递归求阶乘
#用递归函数求 n 阶乘的值 def factorial(i): : else: )# sum=n*(n-)!所以直接调用自身 n=int(input('请输入阶乘数:')) ): print('%d ...
- 安装 bochs-x
sudo apt-get install bochs-x
- MAC终端安装grunt--javascript世界得构建工具
祝贺我成为前端啦!~~从年前得小测试到今年得前端,成功转型!我真是一个进步得好青年,好少女! 这两天出去受虐,面了两家前端,表现非常不好,还是回到我现在得公司好好沉淀技术,做前端,要经常性得整理总结, ...
- 雷林鹏分享:Ruby CGI方法
Ruby CGI方法 以下为CGI类的方法列表: 序号方法描述 1CGI::new([ level="query"]) 创建 CGI 对象.query可以是以下值: query: ...
- maven 工程mybatis自动生成实体类
generatorConfig.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ge ...
- module.exports和exports
require 用来加载代码,而 exports 和 module.exports 则用来导出代码.但很多新手可能会迷惑于 exports 和 module.exports 的区别,为了更好的理解 e ...
- 1、lambda表达式
lambda表达式中的类型是通过上下文推断出来的,类似String[] strArr = {"as","sd"};右边元素的子类型. 匿名内部类的情况:需要引用 ...
- C++ 4 种具有更 为准确语义的新强制转换类型
1. static_cast<T>() 可用于把指向A 的指针强制转换为指向B 的指针,其约束条件是类B必须是类A的子类.例如:A *obj = new B;B *b = static_c ...