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 ...
随机推荐
- mysql 2
mysql索引原理 初识索引 为什么要索引? 加速查询 读写比10:1左右 什么是索引? 索引在MySQL中也叫是一种“键”,是存储引擎用于快速找到记录的一种数据结构. 索引是应 ...
- python docopt模块详解
python docopt模块详解 docopt 本质上是在 Python 中引入了一种针对命令行参数的形式语言,在代码的最开头使用 """ ""&q ...
- Array和ArrayList不同
Employee[] array = new Employee[10]; ArrayList<Employee> staff = new ArrayList<>(); 不同 A ...
- html5的理解
1.良好的移动性,以移动设备为主 2.响应式设计,以适应自动变化的屏幕尺寸 3.支持离线缓存技术,webStorage本地缓存 4.新增canvas.video.audio等新标签元素,新增特殊内容元 ...
- hashcat使用命令简介
1.指定HASH类型 在HashCat中--hash-type ?参数可以指定要破解的HASH类型,运行hashcat主程序加上--help参数,在* Generic hash types:中可以看到 ...
- mybatis generator 生成中文注释
mybatis generator默认生成 的注释太奇葩了,完全不能拿到生产去用,不过幸亏提供了接口可以自己扩展.长话短说,要生成如下的domain, package com.demo.domain; ...
- 使用UI管理docker
比较全面的对比 wangzi19870227 比较推荐的有两种(http://dockone.io/article/225): Shipyard 和 dockerui https://docs.doc ...
- Windows 登录用户的类型
转载:http://blog.csdn.net/chenlycly/article/details/45419259 1.登录的是超级管理员Administrator 默认情况下,超级管理员Admin ...
- Python3基础 response.read 输出网页的源代码
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- eMMC ext4综述【转】
本文转载自:https://blog.csdn.net/lieye_leaves/article/details/78214410 eMMC ext4综述一.系统的引导启动1.1系统的引导启动http ...