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 ...
随机推荐
- TensorFlow for distributed
TensorFlow for distributed 本目录包括了运行时分布式TensorFlow的实现,其底层使用了gRPC 作为进程内通信的支持库. Quick start 首先,需要构建一个Te ...
- js关于移入移出延迟提示框效果处理
html部分 <div id="div1">我是导航君</div> <div id="div2" style="disp ...
- spring(读取外部数据库配置信息、基于注解管理bean、DI)
###解析外部配置文件在resources文件夹下,新建db.properties(和数据库连接相关的信息) driverClassName=com.mysql.jdbc.Driverurl=jdbc ...
- es数据迁移脚本(python)
#!/usr/bin/python # -*- coding: UTF-8 -*- # 文件名:indiceCreate.py import sys import base64 import time ...
- ajax返回数据
在使用远程js验证检测账户是否存在时,直在发请求后返回值无效,怎样把值返回回来呢重点注意两点 第一点:type不能省略,不能是异步,async: false 第二点:不能在直接请求成功后返回 var ...
- 位运算之a^b
题目链接:https://www.acwing.com/problem/content/91/ 参考链接:https://blog.csdn.net/chaiwenjun000/article/det ...
- python操作串口
import serial test = serial.Serial("COM1",115200)#这里就已经打开了串口 print(test.portstr) test.writ ...
- maven项目出现红色感叹号报错
背景 在eclipse部署maven项目的时候,项目出现红色的感叹号导致项目无法启动. 解决步骤 1.右键项目——>Maven——>Update Project ,弹出下框: 点击OK. ...
- python 函数,闭包
假如有一个函数,实现返回两个数中的较大值: def my_max(x,y): m = x if x>y else y return mbigger = my_max(10,20)print(bi ...
- 在cygwin下创建的文件位于windows的哪个目录下?
答: 1. C盘的SPB_Data目录下 2. 在cygwin下通过pwd命令可以查看,例如: jello@jello ~ $ pwd /cygdrive/c/SPB_Data (/cygdrive/ ...