HDU-1501-Zipper-字符串的dfs】的更多相关文章

意甲冠军  是否可以由串来推断a,b字符不改变其相对为了获取字符串的组合c 本题有两种解法  DP或者DFS 考虑DP  令d[i][j]表示是否能有a的前i个字符和b的前j个字符组合得到c的前i+j个字符  值为0或者1  那么有d[i][j]=(d[i-1][j]&&a[i]==c[i+j])||(d[i][j-1]&&b[i]==c[i+j])   a,b的下标都是从1開始的  注意0的初始化 #include<cstdio> #include<cs…
题目大意:输入有一个T,表示有T组测试数据,然后输入三个字符串,问第三个字符串能否由第一个和第二个字符串拼接而来,拼接的规则是第一个和第二个字符串在新的字符串中的前后的相对的顺序不能改变,问第三个字符串能否由前两个得到. 解题报告:这题用dfs,反过来,将第三个字符串按照从前到后的顺序,看能否拆成第一个和第二个字符串,不过这题如果只是这样搜索的话,很明显会超时,所以要减掉其中一些重复的其情况,定义一个二维数组hash[i][j],初始化都为0,然后如果将hash[i][j]标记为1表示第一个字符…
HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in…
题目链接: HDU - 1501 Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order.For examp…
题目大意:个字符串.此题是个非常经典的dfs题. 解题思路:DFS 代码如下:有详细的注释 /* * 1501_2.cpp * * Created on: 2013年8月17日 * Author: Administrator */ #include <iostream> using namespace std; char str1[201], str2[201], str3[401]; int len1, len2, len3; bool flag; bool hash[201][201];…
Problem Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in its original order. For e…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1501 思路:题目要求第三个串由前两个组成,且顺序不能够打乱,搜索大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<math.h> #include<string.h> #include<vector> #include<queue> #incl…
Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4884    Accepted Submission(s): 1742 Problem Description Given three strings, you are to determine whether the third string can be formed…
题意: 给三个字符串str1.str2.str3 问str1和str2能否拼接成str3.(拼接的意思可以互相穿插) 能输出YES否则输出NO. 思路: 如果str3是由str1和str2拼接而成,str1的前i个字符和str2的前j个字符一定构成str3的前i+j个字符.(因为拼接必须保证字符的顺序不变) 所以,,,这算是个变形的最长公共子序列? DP方程:dp[i][j]:str3的前i+j个字符能否由str1的前i个字符和str2的前j个字符拼接而成.布尔型. 看代码,, 代码: char…
HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10886 Accepted Submission(s): 3925 Problem Description Given three strings, you are to determine whether the third str…