hdu 6170 Two strings dp模拟
来源:互联网 发布:数据分析工具有哪些 编辑:程序博客网 时间:2024/05/21 17:01
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
题意:给你两个含通配符的字符串,是否能匹配。
注意 a* 可以匹配空字符串
思路:模拟递推过程。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN = 3005;char s1[MAXN], s2[MAXN];int dp[MAXN][MAXN];int main(){ int t; scanf("%d", &t); getchar(); while(t--) { gets(s1+1); gets(s2+1); int len1=strlen(s1+1); int len2=strlen(s2+1); memset(dp, 0, sizeof(dp)); dp[0][0]=true; for(int i=1; i<=len2; ++i) { for(int j=1; j<=len1; ++j) { if(s2[i]==s1[j]||s2[i]=='.') dp[i][j]|=dp[i-1][j-1]; else if(s2[i]=='*') { if(s1[j]==s1[j-1]) dp[i][j]|=dp[i][j-1];//可以是代表多个字符 dp[i][j]|=dp[i-1][j];//可以是一个字符,a*为a dp[i][j-1]|=dp[i-2][j-1];//可以是空字符; } } } if(dp[len2][len1]) puts("yes"); else puts("no"); } return 0;}
- 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)
- HDU 6170 Two strings dp || 正则
- hdu 6170 Two strings (dp)
- HDU 6170 Two strings (DP)
- HDU 6170 Two strings(DP)
- hdu 6170 Two strings
- HDU 6170:Two strings
- HDU 6170 Two strings
- hdu 6170 Two strings
- Android高级绘图之复杂动效开发
- 自动化测试(python+selenium)入门(一)
- 数据库-面试题-MySQL数据库的优化方法
- OpenCV 与 Caffe python 接口加载图片 数据转换方法
- UI12-分段视图
- hdu 6170 Two strings dp模拟
- forEach 和 map 的区别
- 【转】jar包和war包的介绍和区别
- 晚餐
- Hdu 6170 Two strings【思维+Dp】
- sso单点登录,HTTP跳转HTTPS登录后回跳HTTP
- 适配器模式
- onvif协议框架搭建
- javascript实现把指定元素移动到第一位