Giving two strings and you should judge if they are matched. 

The first string contains lowercase letters and uppercase letters. 

The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”. 

. can match any letter, and * means the front character can appear any times. For example, “a.b” can match “acb” or “abb”, “a*” can match “a”, “aa” and even empty string. ( “*” will not appear in the front of the string, and there will not be two consecutive “*”.

Input

The first line contains an integer T implying the number of test cases. (T≤15) 

For each test case, there are two lines implying the two strings (The length of the two strings is less than 2500).

Output

For each test case, print “yes” if the two strings are matched, otherwise print “no”.

Sample Input

3
aa
a*
abb
a.*
abb
aab

Sample Output

yes
yes
no

题意:给两个字符串,a固定,b由英文字符和*和.组成,“.”可以变成任意字符,“*”和前一字符一样,且前一个字符的数量为任意多个;求是否可让b变成和a一样‘;

题解:DP;dp[i][j]表示字符串b从1~i与a从1~j是否完全匹配;

由于字符不为空,且第一个字符不为*,没连续的*;

如果b第二个为“*”,的话dp[2][0]=1;

如果b[i]==a[j] ,则dp[i][j]可以由dp[i-1][j-1]转化而来;

如果b[i]==".",则b[i]可以为任何字符,dp[i][j]可有由dp[i-1][j-1]转化而来;

如果b[i]=="*":

1.如果匹配0则dp[i][j]由dp[i-2][j]转化而来,如果匹配1个,dp[i][j]=dp[i-1][j];

2.如果匹配多个 dp[i][j] = max(dp[i][j],max(dp[i][j-1],dp[i-1][j-1]));

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx = 3e3+10;
int n,m,len1,len2;
char str[mx],stc[mx];
int dp[mx][mx];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",str+1);
scanf("%s",stc+1);
len1 = strlen(str+1);
len2 = strlen(stc+1);
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(int i=1;i<=len2;i++)
{
if(i==2&&stc[i]=='*') dp[i][0] = 1;
for(int j=1;j<=len1;j++)
{
if(isalpha(stc[i]))
{
if(str[j]==stc[i]) dp[i][j] = dp[i-1][j-1];
}
else if(stc[i]=='.') dp[i][j] = dp[i-1][j-1];
else
{
dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i-2][j]));
if((dp[i][j-1]||dp[i-1][j-1])&&str[j]==str[j-1])
dp[i][j] = max(dp[i][j],max(dp[i][j-1],dp[i-1][j-1]));
}
}
}
puts(dp[len2][len1]?"yes":"no");
}
return 0;
}

(全国多校重现赛一) J-Two strings的更多相关文章

  1. (全国多校重现赛一) H Numbers

    zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...

  2. (全国多校重现赛一)F-Senior Pan

    Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...

  3. (全国多校重现赛一)D Dying light

    LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his ...

  4. (全国多校重现赛一)E-FFF at Valentine

    At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, ...

  5. (全国多校重现赛一)B-Ch's gifts

    Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...

  6. (全国多校重现赛一)A-Big Binary Tree

    You are given a complete binary tree with n nodes. The root node is numbered 1, and node x's father ...

  7. 长春理工大学第十四届程序设计竞赛(重现赛)J.Printout

    链接:https://ac.nowcoder.com/acm/contest/912/J 题意: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字社,小r一看价格:总打印页数 ...

  8. 长春理工大学第十四届程序设计竞赛(重现赛)J

    J.Printout 题目:链接:https://ac.nowcoder.com/acm/contest/912/J 题目: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字 ...

  9. 2019CCPC秦皇岛赛区(重现赛)- J

    链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=872 题意: 鉴纯夏是一名成绩不太好的高中生. ...

随机推荐

  1. 小白学 Python(23):Excel 基础操作(上)

    人生苦短,我选Python 前文传送门 小白学 Python(1):开篇 小白学 Python(2):基础数据类型(上) 小白学 Python(3):基础数据类型(下) 小白学 Python(4):变 ...

  2. tap事件封装

    <!DOCTYPE html> <html lang="zh"> <head>     <meta charset="UTF-8 ...

  3. centos6官网镜像dvd1和dvd2的解释

  4. PHP Laravel 6.2 中用于用户登录的新密码确认流程

    Laravel 发布了 v6.2 版本,它添加了一个新的密码确认功能,该功能使你可以要求已登录的用户重新输入密码,然后才能访问路由. 在你执行敏感操作的时候,这个功能就类似GitHub确认对话框.在 ...

  5. dubbo分布式Service不可以创建Error creating bean with name 'XXXXXX'

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService' ...

  6. 红帽学习笔记[RHCE]网络配置与路由转发

    目录 网络配置基本的IPV4与IPV6 拓扑图 操作 新加一块网卡 将增加的网卡分别加到两台虚拟机上 在两台虚拟机上配置IPV4与 IPV6 配置域名访问 拓展路由转发 拓扑图 操作 关于网关设置 重 ...

  7. Mac上安装并配置JDK

    1,下载 点击 官网 ,进入下载界面, 同意协议内容 找到对应的Mac版本, 2,安装 安装下载下来的文件,期间会要求输入一次电脑密码,然后自动安装完. 如果显示文件已经损坏,打开 终端 输入 sud ...

  8. Install gitlab

    yum install -y curl policycoreutils-python openssh-server postfix wget wget https://mirrors.tuna.tsi ...

  9. 配置k8s集群context-rbac实践

    说明 在openshift环境中,可以通过oc project {project_name}命令来切换project,那么在k8s中式如何切换namespace的呢?(ocp的project即相当于k ...

  10. 堆 堆排序 优先队列 图文详解(Golang实现)

    引入 在实际应用中,我们经常需要从一组对象中查找最大值或最小值.当然我们可以每次都先排序,然后再进行查找,但是这种做法效率很低.哪么有没有一种特殊的数据结构,可以高效率的实现我们的需求呢,答案就是堆( ...