三个串必须要一起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. 解决asp.net中HTML中talbe的行高被内容撑的变高的问题

    将asp.net页面中的如下语句: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  2. alert弹窗方法1

    1.代码 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv=&quo ...

  3. linux /etc/security/limits.conf的相关说明

    暂时粘贴他人的地址,后续会整理后放出. 原文地址:http://blog.csdn.net/taijianyu/article/details/5976319

  4. linux下安装nmon监控工具

    1.首先下载压缩包 wget http://sourceforge.net/projects/nmon/files/download/nmon_x86_12a.zip/download 2.解压并修改 ...

  5. Introduction to Mathematical Thinking - Week 3

    there exists and all there exists 证明根号2是无理数 all 习题 3. Which of the following formal propositions say ...

  6. getFullYear 方法

    返回 Date 对象中用本地时间表示的年份值. dateObj.getFullYear() 必选项 dateObj 参数为 Date 对象. 说明要获取用全球标准时间 (UTC)表示的年份值,请使用 ...

  7. velocity 遍历EventHandler Iterator

    EventHandlerUtil 类的 iterateOverEventHandlers方法 for (Iterator i = handlerIterator; i.hasNext();){ Eve ...

  8. 如何安装secureCRT8.1破解

    安装地址 网盘: https://pan.baidu.com/s/1iGxi6BTCMC_jewCwcUHhgA 密码: u6jq 安装教程 1.点击安装 2.全部默认即可,安装完成之后再桌面上右击该 ...

  9. Android系统移植与调试之------->如何修改Android手机显示的4G信号强度的格子数

    在修改显示的信号强度之前,先了解一下什么是dB,什么是dBm? 1.dB dB是一个表征相对值的值,纯粹的比值,只表示两个量的相对大小关系,没有单位,当考虑甲的功率相比于乙功率大或小多少个dB时, 按 ...

  10. xml数据发送请求,读取xml

    # coding:utf-8 import requests url = "http://httpbin.org/post" # python3字符串换行,在右边加个反斜杠 bod ...