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

HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9

时间:2017-08-24 00:08:39      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:==   else   set   string   div   its   pre   log   scan   

/*
HDU 6170 - Two strings [ DP ]  |  2017 ZJUT Multi-University Training 9
题意:
	定义*可以匹配任意长度,.可以匹配任意字符,问两串是否匹配
分析:
	dp[i][j] 代表B[i] 到 A[j]全部匹配
	然后根据三种匹配类型分类讨论,可以从i推到i+1
	复杂度O(n^2)
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 2505;
int t;
char a[N], b[N];
int la, lb;
bool dp[N][N];
int main()
{
    scanf("%d", &t);
    while (t--)
    {
        scanf("%s%s", a+1, b+1);
        la = strlen(a+1);
        lb = strlen(b+1);
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 1; i <= lb; i++)
        {
            if (b[i] == ‘.‘)
            {
                for (int j = 1; j <= la; j++) dp[i][j] = dp[i-1][j-1];
            }
            else if (b[i] == ‘*‘)
            {
                for (int j = 0; j <= la; j++) dp[i][j] = dp[i-2][j];
                for (int j = 0; j <= la; )
                {
                    if (dp[i-1][j])
                    {
                        int k = j;
                        while (a[k] == a[j])
                        {
                            dp[i][k] = 1;
                            k++;
                        }
                        j = k;
                    }
                    else j++;

                }
            }
            else
            {
                for (int j = 1; j <= la; j++)
                    if (dp[i-1][j-1] && a[j] == b[i])
                        dp[i][j] = 1;
            }
        }
        if (dp[lb][la]) puts("yes");
        else puts("no");
    }
}

  

HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9

标签:==   else   set   string   div   its   pre   log   scan   

原文地址:http://www.cnblogs.com/nicetomeetu/p/7420754.html

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