hdu zipper 1501

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

记忆化搜索

由于第三个串是由 前两个串按顺序组成的 那么从前两个串的 第一位 和 第三个串的第一位 开始比 相等就比下一个能比到尾就行了

从这些路径中找出可行的 记忆化搜索

代码:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
using namespace std;
char a[205];
char b[205];
char c[405];
bool flag[205][205];
int lena,lenb,lenc;
int m=1;
int dfs(int x,int y,int z)
{
    if(z>lenc)
    return 1;
    if(flag[x][y])
    return 0;
    flag[x][y]=1;
    if(x>lena+1||y>lenb+1)
    return 0;
    if(a[x]==c[z]&&dfs(x+1,y,z+1))
    return 1;
    if(b[y]==c[z]&&dfs(x,y+1,z+1))
    return 1;
    return 0;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%s%s%s",a+1,b+1,c+1);
        memset(flag,0,sizeof(flag));
         lena=strlen(a+1);
         lenb=strlen(b+1);
         lenc=strlen(c+1);
         if(dfs(1,1,1))
         printf("Data set %d: yes\n",m++);
         else
         printf("Data set %d: no\n",m++);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值