当前位置:网站首页>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);
}
}
边栏推荐
- OpenGL ES: (1) OpenGL ES的由来 (转)
- SOE spatial analysis server MySQL and PostGIS geospatial database of Postgres anti injection attack
- el-table 动态表头渲染 固定第一列 高度问题
- DHT11 温湿度传感器
- 可动的机械挂钟
- 让田头村变甜头村的特色农产品是仙景芋还是白菜
- srpingboot security demo
- Cjc8988 Low Power Stereo codec with 2 stereo headphone drivers
- C language beginner level - realize the minesweeping game
- DEV XPO对比之XAF BO
猜你喜欢
表格中el-tooltip 实现换行展示
Dear pie users, I want to confess to you!
69 cesium code datasource loading geojson
Transformer le village de tiantou en un village de betteraves sucrières
Thesis learning record essay multi label lift
让厦门灌口镇田头村变甜头村的特色农产品之一是蚂蚁新村
FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述
π disk, turning your computer into a personal private cloud
Some errors encountered in MySQL data migration
three.js小结
随机推荐
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
excel初级应用案例——杜邦分析仪
Infinite horizontal marble game
JDBC database operation
Record currency in MySQL
DEV XPO对比之XAF BO
2022 the 8th China International "Internet +" college student innovation and entrepreneurship competition industry proposition track is open for registration!
Make: g++: command not found
Make Tiantou village sweet. Is Xianjing taro or cabbage the characteristic agricultural product of Tiantou Village
【笔记】电商订单数据分析实战
What if the data in the cloud disk is harmonious?
Solve the problem of garbled files uploaded by Kirin v10
栈题目:解析布尔表达式
Skywalking integrated Nacos dynamic configuration
记磁盘扇区损坏导致的Mysql故障排查
Cjc8988 Low Power Stereo codec with 2 stereo headphone drivers
restframework-simpleJWT重写认证机制
My experience from technology to product manager
OpenGL ES: (5) OpenGL的基本概念、OpenGL ES 在屏幕产生图片的过程、OpenGL管线(pipeline)
【文件系统】如何在ubi之上运行squashfs