三个串必须要一起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. SCSS详解

    SCSS入门 CSS预处理器 定义了一种新的专门的编程语言,编译后成正常的CSS文件.为CSS增加一些编程的特性,无需考虑浏览器的兼容问题,让CSS更加简洁,适应性更强,可读性更佳,更易于代码的维护等 ...

  2. hoj 2739 中国邮局问题

    /*若原图的基图不连通, 或者存在某个点的入度或出度为 0 则无解. 统计所有点的入度出度之差 Di, 对于 Di > 0 的点, 加边(s, i, Di, 0); 对于 Di < 0 的 ...

  3. 对 pthread 做的一个简陋封装

    参考自 pthreadcc 库的 ThreadBase 类 用法:继承该类,重写 execute 方法,调用父类的 launchThread 方法启动线程 Thread.h // // Thread. ...

  4. 我的Android进阶之旅------>【强力推荐】Android开源图表库XCL-Charts版本发布及展示页

    因为要做图表相关的应用,后来百度发现了一个很好的Android开源图表库(XCL-Charts is a free charting library for Android platform.) 下面 ...

  5. Android系统移植与调试之------->如何修改开机动画的两种方式剖析

    首先,我们先来分析一下源码: frameworks/base/cmds/bootanimation/BootAnimation.cpp 首先看一下定义的常量: BootAnimation::ready ...

  6. 判断数A和数B中有多少个位不相同

    1. A & B,得到的结果C中的1的位表明了A和B中相同的位都是1的位:2. A | B, 得到的结果D中的1的位表明了A和B在该位至少有一个为1的位,包含了A 与 B 都是1的位数,经过前 ...

  7. microsoft cl.exe 编译器

    cl.exe是visual stdio 内置的编译器,visual stdio包含各种功能,有些功能可能这辈子都用不到,体积庞大,如果是 开发比较大或者有图形的项目,vs是首选.更多情况时更喜欢使用文 ...

  8. linux各个文件夹作用

    linux /bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基点,比如用户user的主目录就是/ho ...

  9. 【鸟哥的Linux私房菜】笔记2

    Linux的应用 学习资源整理 安装记录 >< 1.Linux的应用: 网络服务器 数据库 学术机构的高效运算任务 嵌入式系统 ... 2.挂载与磁盘分区 学习资源整理 学习 1.书上的网 ...

  10. 【Head First Servlets and JSP】笔记5:HttpServletResponse resp

    [HttpServletResponse resp] [由servlet处理响应] 1.一般可以用通过resp获得一个输出流(writer),然后通过输出流将HTML写入响应.例如: resp.set ...