/* 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"); } }