当前位置:网站首页>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);
}
}
边栏推荐
- OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
- linux 关闭redis 进程 systemd+
- restframework-simpleJWT重写认证机制
- 论文学习记录随笔 多标签之LSML
- Thoughts on a "01 knapsack problem" expansion problem
- three.js小结
- My experience from technology to product manager
- Bat operation FTP upload and download command
- Huluer app help
- excel可视化
猜你喜欢
随机推荐
Crossing sect · paipan + Siyuan notes = private notebook
Small guide for rapid completion of mechanical arm (VI): stepping motor driver
Code shoe set - mt3114 · interesting balance - explain it with examples
c# Xml帮助类
excel动态图表
Primary application case of Excel DuPont analyzer
uniapp树形层级选择器
Servlet
让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村
基于LabVIEW的计时器
3D printer threading: five simple solutions
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
golang panic recover自定义异常处理
restframework-simpleJWT重写认证机制
让田头村变甜头村的特色农产品是仙景芋还是白菜
Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
Oracle 序列+触发器
kubeadm搭建kubenetes 集群(个人学习版)
This is the necessary software for college students 𞓜 knowledge management
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








