Two strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 485    Accepted Submission(s): 178

Problem Description
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
 
Source
 千千详细分析

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
#define PI acos(-1.0)
int t;
char a[],b[];
int dp[][];
int main()
{
scanf("%d",&t);
while(t--){
scanf("%s",a+);
scanf("%s",b+);
memset(dp,,sizeof(dp));
int lena=strlen(a+);
int lenb=strlen(b+);
dp[][]=;
for(int i=;i<=lenb;i++){
if(i==&&b[i]=='*')
dp[i][]=;
for(int j=;j<=lena;j++){
if(b[i]=='.'||b[i]==a[j])
dp[i][j]=dp[i-][j-];
else if(b[i]=='*'){
dp[i][j]=dp[i-][j]|dp[i-][j];
if((dp[i-][j-]||dp[i][j-])&&a[j-]==a[j])
dp[i][j]=;
}
}
}
if(dp[lenb][lena]==)
printf("yes\n");
else
printf("no\n");
}
return ;
}

HDU 6170 dp的更多相关文章

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

    /* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...

  2. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. HDU 5928 DP 凸包graham

    给出点集,和不大于L长的绳子,问能包裹住的最多点数. 考虑每个点都作为左下角的起点跑一遍极角序求凸包,求的过程中用DP记录当前以j为当前末端为结束的的最小长度,其中一维作为背包的是凸包内侧点的数量.也 ...

  4. 2017多校第9场 HDU 6170 Two strings DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 题意:给了2个字符串,其中第2个字符串包含.和*两种特别字符,问第二个字符串能否和第一个匹配. ...

  5. HDU 6170 Two strings (dp)

    /** * 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 * 字符串match, '.'代表匹配任意一个字符,"*" 代表 ...

  6. HDU 6170 Two strings( DP+字符串匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=6170 题目大意: 给出两个字符串s1和s2(长度小于等于2500). s1是一个正常的包含大小写字母的字符串,s ...

  7. hdu 6170 Two strings dp

    Two strings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Prob ...

  8. 2017ACM暑期多校联合训练 - Team 9 1010 HDU 6170 Two strings (dp)

    题目链接 Problem Description Giving two strings and you should judge if they are matched. The first stri ...

  9. HDU 1069 dp最长递增子序列

    B - Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

随机推荐

  1. Luogu P4071 [SDOI2016]排列计数

    晚上XZTdalao给我推荐了这道数论题.太棒了又可以A一道省选题了 其实这道题也就考一个错排公式+组合数+乘法逆元 我们来一步一步分析 错排公式 通俗的说就是把n个1~n的数排成一个序列A,并使得所 ...

  2. matplotlib 雷达图2

    说明 搞了一个最新版本的雷达图,比以前那个美观. 不多说,代码奉上: 完整代码 ''' matplotlib雷达图 ''' import numpy as np import matplotlib.p ...

  3. Scala学习(二)练习

    Scala控制结构和函数&练习 1. 一个数字如果为正数,则它的signum为1:如果是负数,则signum为-1:如果为0,则signum为0:编写一个函数来计算这个值 简单逻辑判断: 测试 ...

  4. Jmeter(十八)_Ubuntu部署jmeter与ant

    Docker部署接口自动化持续集成环境第三步,容器化Jmeter与ant! 接上文:Docker_容器化jenkins 为了整合接口自动化的持续集成工具,我将jmeter与ant都部署在了Jenkin ...

  5. Docker部署Registry私有镜像库

    拉取镜像 docker pull registry:2.6.2   生成账号密码文件,这里采用htpasswd方式认证 docker run --rm --entrypoint htpasswd re ...

  6. LintCode——交叉字符串

    描述:给出三个字符串:s1.s2.s3,判断s3是否由s1和s2交叉构成. 样例:s1 = "aabcc" s2 = "dbbca" - 当 s3 = &quo ...

  7. 如何基于 K8S 多租能力构建 Serverless Container

    当前 Kubernetes 已经成为名副其实的企业级容器编排规范,很多云平台都开始提供兼容 Kubernetes 接口的容器服务.而在多用户支持方面,多数平台选择直接提供专属虚机集群,用户需要花费大量 ...

  8. 团队作业Week5

    每个团队开一个讨论会,协商讨论团队贡献分的分配方式.每个团队的团队贡献分为50分/人.每个人分数不能相同,请详细说明分数的分配规则. 可参考这个博客. 截止时间:2014-10-27

  9. 实验 六:分析linux内核创建一个新进程的过程

    实验六:分析Linux内核创建一个新进程的过程 作者:王朝宪  <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029 ...

  10. NBPL团队总结

    我们团队钱多多记账软件项目从2017年12月号开始,历时两个周.这两个周,我们从头学起,学到了很多新的知识,对一些概念有了认知,关于团队协作,关于团队建设,关于Android开发.回顾前两周,我们一致 ...