当前位置:网站首页>HDU - 1501 Zipper(记忆化深搜)
HDU - 1501 Zipper(记忆化深搜)
2022-07-01 06:07:00 【大 聪 明】
传送门
题意:给出3个字符串a,b,c,问c是否的a,b穿插后的结果,也就是在a,b的字符顺序不改变的情况下组合在一起,a,b的字符串长度小于200
分析:直接深搜的话,复杂度是2^200,所以要用到记忆化,是空间也缓解时间,标记之前走过的情况。搜索中要记录a,b,c长度,c的长度等于ab长度的和,所以book[a][b]代表同一种情况,标记一下下次再走到这一步就return;
AC代码:
#include<bits/stdc++.h>
using namespace std;
int inf=0x3f3f3f3f;
int l1,l2,l3;
char a[210],b[210],c[420];
int book[210][210];
int flag;
void dfs(int t1,int t2,int t3)
{
if(t3==l3)
{
flag=1;
return;
}
if(book[t1][t2])
return;
book[t1][t2]=1;
if(a[t1]==c[t3])
dfs(t1+1,t2,t3+1);
if(b[t2]==c[t3])
dfs(t1,t2+1,t3+1);
}
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
memset(book,0,sizeof(book));
flag=0;
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
l1=strlen(a);
l2=strlen(b);
l3=strlen(c);
dfs(0,0,0);
if(flag==1)
printf("Data set %d: yes\n",i);
else printf("Data set %d: no\n",i);
}
}
边栏推荐
- Know the future of "edge computing" from the Nobel prize!
- El tooltip in the table realizes line breaking display
- 从诺奖知“边缘计算”的未来!
- 指数法和Random Forest实现山东省丰水期地表水体信息
- Essay learning record essay multi label Global
- SystemVerilog学习-06-类的封装
- highmap gejson数据格式转换脚本
- This is the necessary software for college students 𞓜 knowledge management
- TIDB数据库特性总结
- el-table 动态表头渲染 固定第一列 高度问题
猜你喜欢

Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills

Thesis learning record essay multi label lift

PLA不粘貼在床上:6個簡單的解决方案

PLA不粘贴在床上:6个简单的解决方案
![Pit of kotlin bit operation (bytes[i] and 0xff error)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
Pit of kotlin bit operation (bytes[i] and 0xff error)

可动的机械挂钟

FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述

SystemVerilog学习-10-验证量化和覆盖率

CJC8988带2个立体声耳机驱动器的低功率立体声编解码器

68 cesium code datasource loading czml
随机推荐
Preliminary level of C language -- selected good questions on niuke.com
Record currency in MySQL
Oracle 序列+触发器
jdbc 数据库操作
Transformer le village de tiantou en un village de betteraves sucrières
TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
LED lighting used in health lighting
excel可视化
PLA不粘貼在床上:6個簡單的解决方案
Save data in browser to local file
Code shoe set - mt3149 · and - the data is not very strong. Violent pruning can deceive AC
Call us special providers of personal cloud services for College Students
Dear pie users, I want to confess to you!
扩展点系列之SmartInstantiationAwareBeanPostProcessor确定执行哪一个构造方法 - 第432篇
kotlin位运算的坑(bytes[i] and 0xff 报错)
Oracle sequence + trigger
The row and column numbers of each pixel of multi-source grid data in the same area are the same, that is, the number of rows and columns are the same, and the pixel size is the same
Debug details under pycharm
Using Baidu map to query national subway lines
Highmap gejson data format conversion script