当前位置:网站首页>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);
}
}
边栏推荐
- ONEFLOW source code parsing: automatic inference of operator signature
- How to transmit and share 4GB large files remotely in real time?
- 穿越派 你的数据云行
- Primary application case of Excel DuPont analyzer
- TIDB数据库特性总结
- Solve the problem of garbled files uploaded by Kirin v10
- SOE空间分析服务器 MySQL以及PostGres的地理空间库PostGIS防注入攻击
- kubeadm搭建kubenetes 集群(个人学习版)
- π盘,让您电脑变成个人的私有云
- 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
猜你喜欢
随机推荐
基于LabVIEW的计时器
Fixed height of the first column in El table dynamic header rendering
数据库问题,如何优化Oracle SQL查询语句更快,效率更高
make: g++:命令未找到
分布式锁实现
Small guide for rapid completion of mechanical arm (VI): stepping motor driver
解决麒麟V10上传文件乱码问题
Skywalking integrated Nacos dynamic configuration
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
PLA不粘貼在床上:6個簡單的解决方案
可动的机械挂钟
TIDB数据库特性总结
Pla ne colle pas sur le lit: 6 solutions simples
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
linux 关闭redis 进程 systemd+
c# Xml帮助类
从诺奖知“边缘计算”的未来!
论文学习记录随笔 多标签之GLOCAL
OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
OpenGL es: (1) origin of OpenGL es (transfer)









