(全国多校重现赛一) J-Two strings
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的更多相关文章
- (全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...
- (全国多校重现赛一)F-Senior Pan
Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...
- (全国多校重现赛一)D Dying light
LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his ...
- (全国多校重现赛一)E-FFF at Valentine
At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, ...
- (全国多校重现赛一)B-Ch's gifts
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...
- (全国多校重现赛一)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 ...
- 长春理工大学第十四届程序设计竞赛(重现赛)J.Printout
链接:https://ac.nowcoder.com/acm/contest/912/J 题意: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字社,小r一看价格:总打印页数 ...
- 长春理工大学第十四届程序设计竞赛(重现赛)J
J.Printout 题目:链接:https://ac.nowcoder.com/acm/contest/912/J 题目: 小r为了打校赛,他打算去打字社打印一份包含世界上所有算法的模板. 到了打字 ...
- 2019CCPC秦皇岛赛区(重现赛)- J
链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=872 题意: 鉴纯夏是一名成绩不太好的高中生. ...
随机推荐
- SVN--服务端安装和设置---centos7
一.安装环境 [root@localhost ~]# getenforce Disabled [root@localhost ~]# systemctl disable firewalld 二.yum ...
- 关于MXNet
关于人工智能,机器学习,深度学习 三者关系:从宏观到微观. 机器学习是人工智能的一部分,深度学习是机器学习的一部分. 基础:大数据. 关于深度学习 深度学习基于神经网络, 关于神经网络:通过叠加网络层 ...
- [LC]219题 Contains Duplicate II (存在重复元素 II )
①英文题目: Given an array of integers and an integer k, find out whether there are two distinct indices ...
- nyoj 1 A + B Problme
A+B Problem 时间限制:3000 ms | 内存限制:65535 KB |难度:0 描述 此题为练手用题,请大家计算一下a+b的值. 输入 输入两个数,a,b 输出 输出a+b的值 样例 ...
- hdu 1166 敌兵布阵 (线段树、单点更新)
敌兵布阵Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- hdu 1205 吃糖果 (抽屉原理<鸽笼原理>)
吃糖果Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submissi ...
- python描述:链表
单链表结构: 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每个结点 ...
- linuxshell编程之数组和字符串处理工具
数组:存放多个元素的连续内存空间. 声明数组:bash-4以后支持除默认的0,1,2……还可以自定义索引格式,此类数组称之为“关联数组” 声明索引数组:declare -a NAME 声明关联数组:d ...
- MacOS安装Docker傻瓜式教程
最近电脑越来越卡了,为了减少系统开销,以及后期维护方便,所以考虑将本地安装一些服务迁移到docker中去管理,这一切的基础是要先有docker服务,所以本文就先记录怎样在mac上安装配置docker, ...
- 献给那些想自建站搭建博客的新人们(实篇)wordpress
实验材料 windows或者linux(因为我是大学操作系统学的是windows,后来服务器转向了linux,所以我将针对window和linux分别进行开展) xampp(最佳php5.6 在7.1 ...