三个串必须要一起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. PHP中mysql_fetch_row()、mysql_fetch_assoc()和mysql_fetch_array()的联系

    总是记不住或者混淆mysql_fetch_row().mysql_fetch_assoc()和mysql_fetch_array()这三个函数的朋友们注意了,今天我在这里给大家总结一下他们之间的关系, ...

  2. 【BZOJ2325】[ZJOI2011]道馆之战 线段树+树链剖分

    [BZOJ2325][ZJOI2011]道馆之战 Description 口袋妖怪(又名神奇宝贝或宠物小精灵)红/蓝/绿宝石中的水系道馆需要经过三个冰地才能到达馆主的面前,冰地中的每一个冰块都只能经过 ...

  3. 巨蟒python全栈开发linux之centos7

    1.crm项目部署回顾(小BOSS) crm部署 nginx+uwsgi+django+mysql nginx    前端 uwsgi+django     后端 mysql   数据支撑 crm是一 ...

  4. JavaWeb 过滤器应用之页面静态化

    页面静态化是把servlet请求的资源所做输出保存到html中, 然后重定向到 html 页面, 二次访问时,这个html已经存在,那么直接重定向,不用再去访问servlet! // StaticFi ...

  5. CentOS 7.4 防火墙&网卡设置

    防火墙 查看防火墙状态 临时关闭防火墙 (关闭的是当前正在运行的防火墙,重启时还是会自启) 彻底关闭防火墙 (开机不会再自启) 开启防火墙 查看防火墙状态 网卡 查看网卡状态

  6. make编译三

    多目标 Makefile 的规则中的目标可以不止一个,其支持多目标,有可能我们的多个目标同时依赖于一个文件,并且其生成的命令大体类似.于是我们就能把其合并起来.但是如果多个目标的生成规则的执行命令是同 ...

  7. 20170421 F110 常见问题

    F110常見問題以及處理方式 1. Vendor中沒有與F110中相同的Payment method 解決辦法: 在Vendor主檔中維護Payment method 2. 結報被Block 解決辦法 ...

  8. Linux服务器维护常用命令

    # uname -a # 查看内核/操作系统/CPU信息 # /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算 ...

  9. 1.8 使用电脑测试MC20的GPRS功能

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  10. vlc做转发的命令

    from:http://blog.csdn.net/linyuejiang/article/details/7498482 将一个udp的多播流转发复制到http流中去 vlc udp://@239. ...