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

Posted nicetomeetu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9相关的知识,希望对你有一定的参考价值。

/*
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的主要内容,如果未能解决你的问题,请参考以下文章

HDU6170 Two strings

hdu 6170 Two strings

HDU 6170 Two strings 思维 DP

2017多校第9场 HDU 6170 Two strings DP

HDU 6170 Two strings (DP)

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