hdu6170(dp)
来源:互联网 发布:大学 知乎 编辑:程序博客网 时间:2024/06/16 17:40
Two strings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1384 Accepted Submission(s): 570
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<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s1[2550];char s2[2550];bool dp[2550][2550];int len1,len2;void solve(){memset(dp,0,sizeof(dp));dp[0][0]=1;if (s2[2]=='*')dp[0][2]=1;for(int i=1;i<=len1;i++){for(int j=1;j<=len2;j++){if(s2[j]=='.'||s2[j]==s1[i])dp[i][j]=dp[i-1][j-1];else if(s2[j]=='*'){dp[i][j]=max(dp[i][j-1],dp[i][j-2]);if (dp[i][j])continue;if (s1[i]==s1[i-1])dp[i][j]=max(dp[i-1][j],dp[i-2][j]);}}}if(dp[len1][len2])printf("yes\n");elseprintf("no\n");}int main(){int t;scanf("%d",&t);while(t--){scanf("%s",s1+1);scanf("%s",s2+1);len1=strlen(s1+1);len2=strlen(s2+1);solve();}}
阅读全文
0 0
- hdu6170(dp)
- hdu6170(dp)
- hdu6170
- HDU6170【DP+树状数组+差分维护】
- Two strings hdu6170 dp递推
- HDU6170-Two strings 多校9 dp
- hdu6170-多看几遍之DP&递推&字符串-Two strings
- HDU6170 Two strings dp 多校联赛第9场
- HDU6170 Two strings(动态规划)
- HDU6170 Two strings(dp,2017 HDU多校联赛 第9场)
- HDU6170-Two strings
- HDU6170-Two strings
- hdu6170 Two strings【regex真好用】
- [正则表达式] hdu6170 two strings
- colors颜色的长度 (来自刘汝佳紫书) dp+dp+dp
- 区间DP -- 石子合并(朴素DP)
- 疯狂 dp(一) 线性 dp
- hdu 3480 Division(DP-DP优化)
- HTTP请求头和响应头
- PHP编程效率的20个要点 (2015-09-25 14:37:49) 转载 ▼ 用单引号代替双引号来包含字符串,这样做会更快一些。因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,
- Unity Canvas UI line Renderer
- 前端对后台传过来是数组进行重新排序显示
- 【二叉树经典问题】106. Construct Binary Tree from Inorder and Postorder Traversal
- hdu6170(dp)
- spring cloud教程---Eureka
- pl sql
- angular2中ViewChild,索引值相关
- Spring Boot : CROS解决跨域问题(七)
- jzoj5336 【NOIP2017提高A组模拟8.24】提米树 (dfs序dp,奇异姿势dp)
- C语言 输入
- url带加号+,get时显示空格
- Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法与解析