hdu 6170 Two strings dp
Two strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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 “*”.
For each test case, there are two lines implying the two strings (The length of the two strings is less than 2500).
aa
a*
abb
a.*
abb
aab
yes
no
类似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的更多相关文章
- 2017多校第9场 HDU 6170 Two strings DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 题意:给了2个字符串,其中第2个字符串包含.和*两种特别字符,问第二个字符串能否和第一个匹配. ...
- HDU 6170 Two strings( DP+字符串匹配)
http://acm.hdu.edu.cn/showproblem.php?pid=6170 题目大意: 给出两个字符串s1和s2(长度小于等于2500). s1是一个正常的包含大小写字母的字符串,s ...
- HDU 6170 - Two strings | 2017 ZJUT Multi-University Training 9
/* HDU 6170 - Two strings [ DP ] | 2017 ZJUT Multi-University Training 9 题意: 定义*可以匹配任意长度,.可以匹配任意字符,问 ...
- HDU 6170 Two strings (dp)
/** * 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6170 * 字符串match, '.'代表匹配任意一个字符,"*" 代表 ...
- 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 ...
- HDU 1011 树形背包(DP) Starship Troopers
题目链接: HDU 1011 树形背包(DP) Starship Troopers 题意: 地图中有一些房间, 每个房间有一定的bugs和得到brains的可能性值, 一个人带领m支军队从入口(房 ...
- hdu 2296 aC自动机+dp(得到价值最大的字符串)
Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 4778 状压DP
一看就是状压,由于是类似博弈的游戏.游戏里的两人都是绝对聪明,那么先手的选择是能够确定最终局面的. 实际上是枚举最终局面情况,0代表是被Bob拿走的,1为Alice拿走的,当时Alice拿走且满足变换 ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
随机推荐
- Python+OpenCV图像处理(十)—— 图像二值化
简介:图像二值化就是将图像上的像素点的灰度值设置为0或255,也就是将整个图像呈现出明显的黑白效果的过程. 一.普通图像二值化 代码如下: import cv2 as cv import numpy ...
- Q_DECL_OVERRIDE
Q_DECL_OVERRIDE也就是c++的override # define Q_DECL_OVERRIDE override 在重写虚函数时会用到, 作用是防止写错虚函数: void keyPre ...
- li设置inline-block后,li左边出现空隙问题。
方法1:在ul设置font-size=0,然后再li再单独设置font-size 方法2:li连着写不要换行,也可以解决. <ul> <li>测试1</li>< ...
- MSVCR120.dll 解决
https://www.microsoft.com/en-us/download/details.aspx?id=40784 装之 from : https://answers.microsoft.c ...
- Docker学习记录--入门了解+安装
Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制, ...
- python元组与购物车程序
#Author:zww ''' 程序:购物车程序 需求: 1.启动程序后,让用户输入工资,然后打印呢商品列表 2.允许用户根据商品编号购买商品 3.用户选择商品后,检测余额是否足够,够就直接扣款,不够 ...
- centos6.5新增加硬盘挂载并实现开机自动挂载
在内网主机新增一个2T硬盘,先关机断电再连接硬盘数据线和电源线! 查看当前磁盘设备信息: [root@tb ~]# fdisk -l WARNING: GPT (GUID Partition Tabl ...
- libcurl 静态库编译
转载:http://www.cnblogs.com/jkcx/p/6406706.html 1.下载最新版的libcurl(官网:http://curl.haxx.se/download.html), ...
- Testng测试报告
执行完测试用例之后,会在项目的test-output(默认目录)下生成测试报告
- topcoder srm 540 div1
problem1 link 设第一个数字为$x$,那么第2到第$n$个数字都可以表示成$a+bx$的形式,其中$b=1$或者$b=-1$.然后可以求出关于$x$的一些范围,求交集即可. problem ...