杭电1501 Zipper DFS

题意::给三个字符串,保证第三个串长度是前两个串长度之和,确定前两个串保持原有的字母顺序能不能拼成第三个串

#include<cstdio>  
#include<cstring>  
#include<algorithm>  
using namespace std;  
int flag;  
int len1,len2,len,vis[300][600];  
char str1[300],str2[300],str[600];  
void dfs(int a,int b,int c)  
{  
    if(a==len1&&b==len2&&c==len)  
    {  
        flag=1;  
        return ;  
    }  
    if(str[c]!=str1[a]&&str[c]!=str2[b])  
        return ;  
    if(a>len1||b>len2||c>len)  
        return ;  
        if(vis[b][c])  
            return ;  
        vis[b][c]=1;  
    if(flag)  
        return ;  
    if(str[c]==str1[a])  
        dfs(a+1,b,c+1);  
  
    if(str[c]==str2[b])  
        dfs(a,b+1,c+1);  
}  
int main()  
{  
    int N,cot=1;  
  
    scanf("%d",&N);  
    while(N--)  
    {  
        scanf("%s%s%s",str1,str2,str);  
        memset(vis,0,sizeof(vis));  
        len1=strlen(str1);  
        len2=strlen(str2);  
        len=strlen(str);  
        flag=0;  
        dfs(0,0,0);  
        if(flag)  
            printf("Data set %d: yes\n",cot++);  
        else  
            printf("Data set %d: no\n",cot++);  
  
    }  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值