当前位置:网站首页>HDU - 1501 zipper (memory deep search)
HDU - 1501 zipper (memory deep search)
2022-07-01 06:12:00 【Great intelligence】
Portal
The question : give 3 A string a,b,c, ask c Yes No a,b Results after interleaving , That is to say a,b Without changing the character order of ,a,b The length of the string is less than 200
analysis : If you search directly and deeply , Complexity is 2^200, So we need to use memorization , Space also relieves time , Mark the past situation . Record in the search a,b,c length ,c The length of is equal to ab Sum of length , therefore book[a][b] Represents the same situation , Mark the next time you get to this point return;
AC Code :
#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);
}
}
边栏推荐
猜你喜欢

扩展点系列之SmartInstantiationAwareBeanPostProcessor确定执行哪一个构造方法 - 第432篇

Multi label lsml for essay learning records
![kotlin位运算的坑(bytes[i] and 0xff 报错)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
kotlin位运算的坑(bytes[i] and 0xff 报错)

Freeswitch dial the extension number

论文学习记录随笔 多标签之LSML

OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)

Skywalking integrated Nacos dynamic configuration

数据库问题,如何优化Oracle SQL查询语句更快,效率更高

2022 年面向初学者的 10 大免费 3D 建模软件

Distributed lock implementation
随机推荐
MySQL怎么存储emoji?
【笔记】电商订单数据分析实战
Factorial divisor (unique decomposition theorem)
Oracle 序列+触发器
Essay learning record essay multi label Global
jdbc 数据库操作
SQL必会题之留存率
Through cooperation with the University of international trade, we can increase efficiency for college students
excel可视化
Arcserver password reset (account cannot be reset)
OpenGL ES: (2) OpenGL ES 与 EGL、GLSL的关系
DHT11 temperature and humidity sensor
Infinite horizontal marble game
OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
Servlet
ArcServer密码重置(账号不可以重置)
skywalking集成nacos动态配置
Thoughts on a "01 knapsack problem" expansion problem
69 cesium code datasource loading geojson
可动的机械挂钟