Zipper

http://acm.hdu.edu.cn/showproblem.php?pid=1501 

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;

#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",x)
#define sfl(x) scanf("%lld",&x)
#define sfs(x) scanf("%s",x)

#define rint register int
#define pb push_back
#define fl() printf("flag!\n")
#define INF 0x3f3f3f3f
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

const int maxn=1e6+9;

bool dp[209][209];

string s1,s2,s3;
int ans;
int len1,len2;

void dfs(int pos1,int pos2,int pos3)
{
    if(ans) return ;
    if(len1==pos1&&len2==pos2)
    {
        ans=1;
        return ;
    }
    if(dp[pos1][pos2])
    {
        return ;
    }

    dp[pos1][pos2]=1;
    if(s1[pos1]==s3[pos3]) dfs(pos1+1,pos2,pos3+1);
    if(s2[pos2]==s3[pos3]) dfs(pos1,pos2+1,pos3+1);

}

int main()
{
    //FAST_IO;
    //freopen("input.txt","r",stdin);

    int T;
    sfi(T);
    int cas=1;
    while(T--)
    {
        mem(dp,0);
        ans=0;
        cin>>s1>>s2>>s3;
        len1=s1.length();
        len2=s2.length();
        dfs(0,0,0);
        printf("Data set %d: %s\n",cas++,ans==1?"yes":"no");

    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值