三个串必须要一起dp

之前刚学了dfs的记忆化搜索的dp方式 觉得很舒服 现学现卖然后两个小时都没有做出来

优化1:之前在dfs中 对每一个pos都会枚举所有可能的组合 结合当前状态来产生新的状态 来决定接下来是直接算还是继续dfs

枚举的结果 只与当前状态和for的区间有关 所以提前预处理出每种情况的结果

优化完跑了个长2W的全?序列 在跑到pos=1W3左右的时候崩溃 手动加栈依然在这里崩溃 猜想是栈崩了。。

优化2:进行完优化1后代码变得好看多了 发现在每一步的结果只与下一步有关 还很严格 于是可以搞一个dp[zt][pos]出来 根据上一个优化算的状态数组直接从pos+1推出来

感想:dfs写dp是挺舒服 但是得是特定的 像数位dp就会很舒服 普通dp就不一定 大概是我接受了for写dp的设定

   dfs写dp得注意深度。。之前写的dp才300层。。1e6的再敢写就剁手

   for循环计数有时候可以用很舒服的预处理给做了

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
using namespace std;
#define L long long
#define pb push_back
#define lala printf("--------\n");
#define ph push
#define rep(i, a, b) for (L i=a;i<=b;++i)
#define dow(i, b, a) for (L i=b;i>=a;--i)
#define fmt(i,n) if(i==n)printf("\n");else printf(" ") ;
#define rnode(i,u) for(L i = head[u] ; i != -1 ; i = b[i].nex)
#define fi first
#define se second
template<class T> inline void flc(T &A, L x){memset(A, x, sizeof(A));}
L read(){L x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} const L mod = 1e9+9 ; char a[1000050] ;
char b[1000050] ;
char c[1000050] ;
L la,lb,lc;
L dp[3][1000050] ;
L G[28][28][28][5][5] ;
void init() {
flc(G,0) ;
rep(aa,0,27) rep(bb,0,27) rep(cc,0,27) {
L La=1,Ra=26;
L Lb=1,Rb=26;
L Lc=1,Rc=26;
if(aa!=27)La=Ra=aa;
if(bb!=27)Lb=Rb=bb;
if(cc!=27)Lc=Rc=cc;
L (&g)[5][5] = G[aa][bb][cc] ;
rep(a,La,Ra)
rep(b,Lb,Rb)
rep(c,Lc,Rc){
g[1][2] += a<b&&b<c ;
g[1][1] += a==b&&b==c ;
g[1][3] += a<b&&b==c ;
g[1][4] += a==b&&b<c ;
g[3][2] += b<c ;
g[3][3] += b==c ;
g[4][2] += a<b ;
g[4][4] += a==b ;
g[2][2] ++ ;
}
}
}
L jfhsb[1000050][5] ;
L zhrsb() {
flc(jfhsb,0) ;
dow(pos,la,1) {
rep(zt,1,4){
L aa,bb,cc;
if(a[pos]=='?')aa=27;else aa=a[pos]-'a'+1;
if(b[pos]=='?')bb=27;else bb=b[pos]-'a'+1;
if(c[pos]=='?')cc=27;else cc=c[pos]-'a'+1;
L ztt2 = (((((dp[0][pos] * dp[1][pos])) % mod ) * dp[2][pos])%mod) ;
L ztt1 = jfhsb[pos+1][1]%mod ;
L ztt3 = jfhsb[pos+1][3]%mod ;
L ztt4 = jfhsb[pos+1][4]%mod ;
L zt1 = (ztt1 * G[aa][bb][cc][zt][1])%mod ;
L zt2 = (ztt2 * G[aa][bb][cc][zt][2])%mod ;
L zt3 = (ztt3 * G[aa][bb][cc][zt][3])%mod ;
L zt4 = (ztt4 * G[aa][bb][cc][zt][4])%mod ;
jfhsb[pos][zt] = (((((zt1+zt2)%mod)+zt3)%mod)+zt4) % mod;
}
}
return jfhsb[1][1] ;
} int main () {
init() ;
L t ;
scanf("%lld" , &t) ;
while(t--){
flc(dp,0) ;
scanf("%s",a+1);
scanf("%s",b+1);
scanf("%s",c+1);
la = strlen(a+1) ; lb = strlen(b+1) ; lc = strlen(c+1) ;
L maxx = max(la,max(lb,lc)) ;
rep(i,la+1,maxx) a[i] = 'a' - 1 ;
rep(i,lb+1,maxx) b[i] = 'a' - 1 ;
rep(i,lc+1,maxx) c[i] = 'a' - 1 ;
a[maxx+1] = '\0' ;
b[maxx+1] = '\0' ;
c[maxx+1] = '\0' ;
la = lb = lc = maxx ;
L wh = 1 ;
for(L i=la;i>=1;i--){
if(a[i]=='?'){
wh %= mod ;
dp[0][i] = wh ;
wh *= 26 ;
wh %= mod ;
}
else {
dp[0][i] = wh ;
}
}
wh = 1 ;
for(L i=lb;i>=1;i--){
if(b[i]=='?'){
wh %= mod ;
dp[1][i] = wh ;
wh *= 26 ;
wh %= mod ;
}
else {
dp[1][i] = wh ;
}
}
wh = 1 ;
for(L i=lc;i>=1;i--){
if(c[i]=='?'){
wh %= mod ;
dp[2][i] = wh ;
wh *= 26 ;
wh %= mod ;
}
else {
dp[2][i] = wh ;
}
}
L ans = zhrsb() ;
printf("%lld\n" , ans) ;
}
}

uvalive 6932的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  5. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  7. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  8. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

  9. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

随机推荐

  1. (转载)java提高篇(五)-----抽象类与接口

    接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 本文是转载的(尊重原著),原文地址:http://www.cnblogs.com/chenssy/p/3376708.html 抽象类 ...

  2. [Spring Data MongoDB]学习笔记--MongoTemplate查询操作

    查询操作主要用到两个类:Query, Criteria 所有的find方法都需要一个query的object. 1. 直接通过json来查找,不过这种方式在代码中是不推荐的. BasicQuery q ...

  3. C++常备知识总结

    1.extern表示是外部函数或外部变量,比如: 1.extern void add(int x,inty);表示该函数主体不在当前模块中,在另一个模块中(文件)2.extern int total; ...

  4. XSL-FO Page Layout

    Simple Layout Let's take a look at the simple page layout that we saw earlier in the course. The sim ...

  5. ehcache.xml配置详解

    一:配置文件案例 <ehcache> <!-- 磁盘存储:将缓存中暂时不使用的对象,转移到硬盘,类似于Windows系统的虚拟内存 path:指定在硬盘上存储对象的路径 --> ...

  6. JavaWeb 之文件上传

    1. 文件上传的要求 1.1 上传对表单的限制 method="post"; enctype="multipart/form-data"; 表单中需要添加文件表 ...

  7. python并发编程&IO模型

    一 IO模型介绍 为了更好地了解IO模型,可先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(n ...

  8. 我的Android进阶之旅------>Android利用温度传感器实现带动画效果的电子温度计

    要想实现带动画效果的电子温度计,需要以下几个知识点: 1.温度传感器相关知识. 2.ScaleAnimation动画相关知识,来进行水印刻度的缩放效果. 3.android:layout_weight ...

  9. Thrift官方安装手册(译)

    本篇是Thrift官网安装文档的翻译,原地址点击这里.Thrift之前是不支持Windows的.但是似乎0.9版本以后已经支持Window了.介绍了Thrift安装的环境要求以及在centos,Deb ...

  10. django事物回滚

    往数据库写入数据时,不经意间就会写入不完整的数据,我们称之为脏数据.事务管理(transaction)可以防止这种情况发生.事务管理一旦检测到写入异常,会执行回滚操作,即要么写入完整的数据,要么不写入 ...