码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 6170

时间:2017-08-23 20:09:26      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:scan   can   eof   size   div   int   代码   pen   匹配   

题意:正则表达式匹配

思路:DP   dp[i][j]表示b串中0~i与0~j是否可以匹配,具体的转移看代码:

#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int maxn=2600;
char a[maxn],b[maxn];
bool dp[maxn][maxn];

int main()
{
    freopen("input.txt","r",stdin);
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%s%s",a+1,b+1);
        memset(dp,0,sizeof dp);
        dp[0][0]=1;
        int sa=strlen(a+1),sb=strlen(b+1);
        for(int i=1;i<=sb;i++)
        {
            if(b[i]==*&&i>=2)dp[i][0]=dp[i-2][0];
            for(int j=1;j<=sa;j++)
            {
                if(b[i]==a[j] || b[i]==.)dp[i][j] = dp[i-1][j-1];
                else if(b[i]==*)
                {
                    dp[i][j] = dp[i-1][j] | dp[i-2][j];
                    dp[i][j] |= dp[i-1][j-1]&&(a[j]==a[j-1]);
                    if(dp[i-1][j])
                    {
                        while(j<=sa&&a[j]==a[j+1])dp[i][++j]=1;
                    }
                }
            }
        }
        if(dp[sb][sa])
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}

 

hdu 6170

标签:scan   can   eof   size   div   int   代码   pen   匹配   

原文地址:http://www.cnblogs.com/MeowMeowMeow/p/7419633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!