hdu 1501 Zipper】的更多相关文章

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…
链接: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…
意甲冠军  是否可以由串来推断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…
题目大意:个字符串.此题是个非常经典的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];…
题目大意:输入有一个T,表示有T组测试数据,然后输入三个字符串,问第三个字符串能否由第一个和第二个字符串拼接而来,拼接的规则是第一个和第二个字符串在新的字符串中的前后的相对的顺序不能改变,问第三个字符串能否由前两个得到. 解题报告:这题用dfs,反过来,将第三个字符串按照从前到后的顺序,看能否拆成第一个和第二个字符串,不过这题如果只是这样搜索的话,很明显会超时,所以要减掉其中一些重复的其情况,定义一个二维数组hash[i][j],初始化都为0,然后如果将hash[i][j]标记为1表示第一个字符…
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…
题意: 给三个字符串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] 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 i…
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…
题意:给定三个串,问c串是否能由a,b串任意组合在一起组成,但注意a,b串任意组合需要保证a,b原串的顺序 例如ab,cd可组成acbd,但不能组成adcb. 分析:对字符串上的dp还是不敏感啊,虽然挺裸的....dp[i][j] 表示a串前i个,b串前j个字母能组成c串前i+j个字母.所以dp[lena-1][lenb-1] = 1; 就行了. 从后往前找就很好找了,从c串最后一个字符开始递归搜索. #include <cstdio> #include <iostream> #i…
Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7813    Accepted Submission(s): 2765 Problem Description Given three strings, you are to determine whether the third string can be formed…
DFS.注意剪枝,0ms. #include <stdio.h> #include <string.h> #define False 0 #define True 1 #define MAXN 201 ]; int len1, len2, len3; int dfs(int e1, int e2, int e3) { int i, flg = False; != e3) // 剩余长度必须相等 return False; ) return True; ; --i) // 控制循环条…
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…
#include<stdio.h> #include<string.h> char s1[300],s2[300],s[500]; int len1,len2,len3,flag,used[300][300]; void dfs(int a,int b,int c) {  if(flag)   return ;  if(c==len3) {   flag=1;   return ;  }  if(used[a][b])   return ;  used[a][b]=1;     …
传送门 题目大意: 问两个词能不能加错拼成一个第三个词. 题目分析: dp方程还是很好想:dp[i][j]表示第一个词前i个和第二个词前j个能不能拼成第三个词的前i+j个. 初始化如果s1[1] == s[1] 那么dp[1][0] = true,s2[1] == s[2]那么dp[0][1] = true, 转移如下:\[dp[i][j] = dp[i - 1][j] (s1[i] == s[i + j) 或者 dp[i][j - 1] (s2[j] == s[i + j]) \] 两者只要一…
这道题目的关键就是逐个搜索的过程 找个时间得复习一下dfs了    这里使用temp作为参照变量 每次比较以后(由于已经排序好) 已temp为参照进行下一次的比较…
Zipper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10465    Accepted Submission(s): 3762 Problem Description Given three strings, you are to determine whether the third string can be formed…
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 example, consider for…
HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201…
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);    正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i…
HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);          正确的…
1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);     正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q…
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm.split.hdu.edu.cn/showproblem.php?pid=1501 这三道题除了输入输出格式不一样,其他都一样,意思是给你三个字符串,问你能不能由前两个组成第三个,要按顺序: 但是hdu5707和poj2192数据太水,直接判断字符个数,然后一个一个的判断先后顺序是否满足即可,但是这…
转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093.1094.1095.1096.1097.1098.1106.1108.1157…
模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 120…
Warcraft Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 957    Accepted Submission(s): 487 Problem Description Have you ever played the Warcraft?It doesn't matter whether you have played it !We…
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116…
HDU分类 http://www.cnblogs.com/ACMan/archive/2012/05/26/2519550.html#2667329 努力A完.方便自己系统A题 不断更新中.................. 水题:1001 1004 简单题1005 找规律 (循环点,周期问题)1008 1012 1013 简单题(有个小陷阱,大数)1017 1018 简单数学题 1019 简单数学题 1020 简单的字符串处理 1021 找规律的数学题,周期81030 简单题,找规律的数学题1…