HDU 6170:Two strings
来源:互联网 发布:java 字符串补位 编辑:程序博客网 时间:2024/05/17 02:59
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 “*”.
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).
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
3aaa*abba.*abbaab
Sample Output
yesyesno
Source
2017 Multi-University Training Contest - Team 9
思路:DP。用d[i][j]=1表示b中前i个字符与a中前j个字符匹配。
#include<bits/stdc++.h>using namespace std;char a[3000],b[3000];int d[3000][3000];int na,nb;int main(){ int T;cin>>T; while(T--) { scanf("%s%s",a+1,b+1); na=strlen(a+1); nb=strlen(b+1); memset(d,0,sizeof d); d[0][0]=1; for(int i=1;i<=nb;i++) { if(i==2&&b[i]=='*')d[i][0]=1; for(int j=1;j<=na;j++) { if(b[i]=='.')d[i][j]=d[i-1][j-1]; else if(b[i]==a[j])d[i][j]=d[i-1][j-1]; else if(b[i]=='*') { d[i][j]=d[i-2][j]|d[i-1][j]; if(a[j-1]==a[j])d[i][j]=d[i][j]|d[i-1][j-1]|d[i][j-1]; } } } puts(d[nb][na]?"yes":"no"); } return 0;}
阅读全文
1 0
- hdu 6170 Two strings
- HDU 6170:Two strings
- HDU 6170 Two strings
- hdu 6170 Two strings
- HDU-6170 Two strings
- hdu 6170 Two strings
- HDU 6170 Two strings
- hdu-6170 Two strings
- hdu 6170 Two strings dp
- hdu 6170 Two strings(DP)
- HDU 6170(Two strings-DP)
- hdu 6170 Two strings(dp)
- hdu 6170 Two strings dp模拟
- Hdu 6170 Two strings【思维+Dp】
- HDU 6170 Two strings (dp)
- HDU 6170 Two strings (二维DP)
- hdu 6170 Two strings(线性dp)
- HDU 6170 Two strings(dp)
- Lua中日期和时间函数详解
- 一直以来对dispatch_sync的误区
- freeswitch系列三 SIP软电话xlite、linphonec接入kamailio+freeswitch
- xcodeDefault.xctoolchain/user/bin/swiftcfailed with exit code 1
- 基于FPGA的RGB565_YCbCr_Gray算法实现
- HDU 6170:Two strings
- CSS 所有属性
- 【LeetCode】653. Two Sum IV
- javaweb项目出现中文乱码问题的解决方案。
- maven项目使用本地jar部署后找不到jar
- POJ 2018 Best Cow Fences + UVA Live 4726 Average 斜率优化DP
- Vim编辑器的简单使用
- Java开发中的23钟设计模式
- 正则表达式各个符号的含义概述