hdu 6170 Two strings(DP)
来源:互联网 发布:开淘宝店名字 编辑:程序博客网 时间:2024/05/20 13:14
Two strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 855 Accepted Submission(s): 338
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
#include <iostream>#include <cstdio>#include <bits/stdc++.h>using namespace std;typedef long long LL;const int N = 2500+10;const LL mod = 1e9+7;int dp[N][N];char s1[N], s2[N];int main(){ int t, ncase=1; scanf("%d", &t); while(t--) { memset(dp,0,sizeof(dp)); scanf("%s %s",s1+1, s2+1); int l1=strlen(s1+1), l2=strlen(s2+1); dp[0][0]=1; for(int i=1;i<=l2;i++) { if(i==2&&s2[i]=='*') dp[2][0]=1;//可能*号消除了前面的字符 for(int j=1;j<=l1;j++) { if(s2[i]=='.') dp[i][j]=dp[i-1][j-1]; else if(s2[i]!='*') { if(s2[i]==s1[j]) dp[i][j]=dp[i-1][j-1]; } else { dp[i][j]=max(dp[i-2][j],dp[i-1][j]); if(s1[j]==s1[j-1]&&(dp[i-1][j-1]||dp[i][j-1])) dp[i][j]=max(dp[i][j],max(dp[i-1][j-1],dp[i][j-1])); } } } if(dp[l2][l1]==1) puts("yes"); else puts("no"); } return 0;}
阅读全文
0 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
- app压力测试Monkey (8)
- sublime text3配置ctrl+鼠标左键进行函数跳转
- 双网卡bond配置
- 【LeetCode】Add to List 606. Construct String from Binary Tree
- codility MaxCounters
- hdu 6170 Two strings(DP)
- spring security cas server默认语言设置为中文
- LinkedList原理及实现学习总结
- JSP 4个域对象-9个内置对象-11个EL隐式对象
- 微信公众平台开发 微信公众平台示例代码分析
- Android Service学习
- 将扩展事件(慢SQL)内容插入到表中并预警
- mysql 导出文件,导入文件大全
- Python访问https报错CERTIFICATE_VERIFY_FAILED