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. c#属性1(Property)

    创建一个只读属性 using System; using System.Collections; using System.Collections.Generic; using System.Glob ...

  2. 为什么 HTTPS 比 HTTP 安全

    HTTP(超文本传输协议)是目前互联网应用最广泛的协议,伴随着人们网络安全意识的加强,HTTPS 被越来越多地采纳.不论是访问一些购物网站,或是登录一些博客.论坛等,我们都被 HTTPS 保护着,甚至 ...

  3. pandas的使用(3)

    pandas的使用(3)

  4. Python Excel 绘制柱形图

    本文主要讲述如何使用Python操作Excel绘制柱形图. 相关代码请参考 https://github.com/RustFisher/python-playground 本文链接:https://w ...

  5. MySql——创建数据表,查询数据,排序查询数据

    参考资料:<Mysql必知必会> 创建数据表 在学习前首先创建数据表和插入数据.如何安装mysql可以看看上个博客https://www.cnblogs.com/lbhym/p/11675 ...

  6. WordPress 去掉底部的自豪的采用WordPress

    WordPress 去掉底部的自豪的采用WordPress  

  7. nyoj 83-迷宫寻宝(二) (计算几何, 叉积)

    83-迷宫寻宝(二) 内存限制:10MB 时间限制:1000ms 特判: No 通过数:2 提交数:6 难度:5 题目描述: 一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个 ...

  8. 树莓派3B/3B+和4B安装OpenCV教程

    安装前准备 在树莓派上拓展文件系统 如果你使用的树莓派为新装的系统,那么第一件事情就是扩展文件系统,以包括microSD卡上的所有空间. 具体步骤如下: 1.在树莓派终端(或者SSH)上输入: $ s ...

  9. ubuntu server 1604 配置网络信息

    对于新安装的linux 服务器(ubuntu server 1604)   一,配置网络 连接网线与路由器 查看系统的网卡信息 ifconfig -a //列出所有的网卡信息,不管启用还是没有启用的 ...

  10. python2中的SSL:CERTIFICATE_VERIFY_FAILED错误的解决办法

    在使用urllib2访问一个自签名的https链接时,对于python2.6以下版本,TLS握手期间是不会检查服务器X509的证书签名是否是CA的可信任根证书.不过python2.7以后改变了这种情况 ...