当前位置:网站首页>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);
}
}
边栏推荐
- Multi label lsml for essay learning records
- TIDB数据库特性总结
- Crossing sect · paipan + Siyuan notes = private notebook
- Through cooperation with the University of international trade, we can increase efficiency for college students
- srpingboot security demo
- 3D printer threading: five simple solutions
- restframework-simpleJWT重写认证机制
- excel初级应用案例——杜邦分析仪
- Primary application case of Excel DuPont analyzer
- It's not that you have a bad mind, but that you haven't found the right tool
猜你喜欢
Huluer app help
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
three.js小结
Talking from mlperf: how to lead the next wave of AI accelerator
Index method and random forest to realize the information of surface water body in wet season in Shandong Province
How to add a gourd pie plate
【笔记】电商订单数据分析实战
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
Advanced drawing skills of Excel lecture 100 (1) - use Gantt chart to show the progress of the project
随机推荐
讓田頭村變甜頭村的特色農產品是仙景芋還是白菜
freeswitch拨打分机号
SystemVerilog学习-07-类的继承和包的使用
PLA not pasted on the bed: 6 simple solutions
DEV XPO对比之UOW
MySQL怎么存储emoji?
Highmap gejson data format conversion script
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
OpenGL ES: (3) EGL、EGL绘图的基本步骤、EGLSurface、ANativeWindow
让田头村变甜头村的特色农产品是仙景芋还是白菜
Differences between in and exists in MySQL
论文学习记录随笔 多标签之GLOCAL
Flink practice -- multi stream merge
Through cooperation with the University of international trade, we can increase efficiency for college students
69 cesium code datasource loading geojson
论文学习记录随笔 多标签之LIFT
Pla ne colle pas sur le lit: 6 solutions simples
Smartinstantiationawarebeanpostprocessor of the extension point series determines which construction method to execute - Chapter 432
69 Cesium代码datasource加载geojson
可动的机械挂钟