Two strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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

类似leetcode第10题;

https://leetcode.com/problems/regular-expression-matching/description/

#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)
const int N=3e3+,maxm=1e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll INF=1e18+; char s[N],p[N];
bool dp[][];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(dp,false,sizeof(dp));
scanf("%s%s",s+,p+);
dp[][]=;
int n=strlen(s+);
int m=strlen(p+);
for(int i=;i<=m;i++)
{
dp[][i]=p[i-]&&dp[][i-];
}
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(p[j]=='*')
{
dp[i][j] = dp[i][j-]|| dp[i][j-] ||( s[i] == p[j-] || ( p[j-] == '.'&& s[i]==s[i-] ) ) && dp[i-][j];
}
else
dp[i][j] = (s[i] == p[j] || p[j] == '.') && dp[i-][j-];
}
}
if(dp[n][m])printf("yes\n");
else printf("no\n");
}
return ;
}

hdu 6170 Two strings dp的更多相关文章

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

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

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

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

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

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

  4. HDU 6170 Two strings (dp)

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

  5. 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 ...

  6. HDU 1011 树形背包(DP) Starship Troopers

    题目链接:  HDU 1011 树形背包(DP) Starship Troopers 题意:  地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...

  7. hdu 2296 aC自动机+dp(得到价值最大的字符串)

    Ring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. HDU 4778 状压DP

    一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...

  9. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

随机推荐

  1. Linux下输出 excel文件

    Linux下输出 excel文件 今日提供给产品需求,需excel文件,故总结要点如下: 1.默认间隔是space_20 2.修改为TAB \t _09 awk '  BEGIN { OFS=&quo ...

  2. 每日linux命令学习-lsattr和chattr

    lsattr和chattr命令 1. lsattr命令 作用: 显示文件属性 语法: lsattr [-adlRvV][files...] 参数: -a 显示所有文件和目录(包括隐藏文件)的属性. - ...

  3. spring总结之二(Bean作用域、依赖注入)

    ### Bean的作用域:单例(singleton),多例(prototype) 1.单例模式:表示在任何地方使用对象,总是一个(对象是唯一的). (笔面试重点) 饿汉式 public class K ...

  4. Centos部署flask项目

    必备: Python2.7(ok) MySQL(ok) git supervisor virtualenv Gunicorn 阿里云服务器(最便宜的就好) 域名(国内万网,国外goDaddy) 我的P ...

  5. TCP/IP 最常见的错误原因码 (errno)列表

    对于在基于 UNIX 的环境中的 TCP/IP 用户,下表列出了某些最常见的错误原因码 (errno).它不是完整的错误列表.可以在文件 /usr/include/sys/errno.h 中找到 Er ...

  6. 阿里云端口失效导致tomcat无法对外提供服务

    下午,我们一个环境启动成功,但是却无法访问,经查看启动日志,如下: Mar 23, 2017 2:15:09 PM org.apache.coyote.http11.AbstractHttp11Pro ...

  7. rpm command

    rpm 实现程序管理 安装:-ivh ,--nodeps ,--replacepkgs 卸载: -e,  --nodeps 升级: -Uvh -Fvh , --nodeps,  --oldpackag ...

  8. 尚硅谷面试第一季-14Redis持久化类型及其区别

    课堂重点: Redis提供了两种不同形式的持久化方案,分别是RDB和AOF. RDB使用Snapshot快照做全量的存储. RDB优缺点: AOF 以日志的方式记录每个写操作,只最佳,不该写文件.增量 ...

  9. uniGUI试用笔记(九)

    uniGUI执行程序部署有3种形式 1.ISAPI模式 部署在IIS或Apache,程序编译为Dll形式,没有试,准备后续专门测试一下. 2.标准执行文件模式 将软件编译成一个独立的Exe文件,包括了 ...

  10. Requests 源码阅读笔记

    models.py class Request(RequestHooksMixin): def __init__(self, method=None, url=None, headers=None, ...