摘要: 题目链接:http://poj.org/problem?id=3974 Manacher算法效率真不错,用后缀数组A的都沙茶了。。 1 //STATUS:C++_AC_235MS_10904KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm> 9 #include<vec 阅读全文
posted @ 2013-04-10 14:42 zhsl 阅读(268) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4513 当时比赛没有A掉的题目,在Manacher匹配的时候维护有序就可以了。 1 //STATUS:C++_AC_156MS_2212KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math.h> 6 #include<iostream> 7 #include<string> 8 #include<algorithm& 阅读全文
posted @ 2013-04-10 14:39 zhsl 阅读(551) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3068 直接用Manacher算法解决即可,先构造字符串,例如 abc -> $#a#b#c# ,第一个‘$’是为了防止溢出字符串。其实也可以不构造字符串,直接去Manacher,具体做法是,当 i 为奇数时为‘#’,为偶数时再去比较。 1 //STATUS:C++_AC_281MS_1348KB 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 #include<math. 阅读全文
posted @ 2013-04-10 14:37 zhsl 阅读(364) 评论(0) 推荐(0) 编辑
摘要: 转送门:http://blog.csdn.net/ggggiqnypgjg/article/details/6645824 这里,我介绍一下O(n)回文串处理的一种方法。Manacher算法.原文地址:http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/ 其实原文说得是比较清楚的,只是英文的,我这里写一份中文的吧。 首先:大家都知道什么叫回文串吧,这个算法要解决的就是一个字符串中最长的回文子串有多长。这个... 阅读全文
posted @ 2013-04-10 14:31 zhsl 阅读(207) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=1699 太爽了这题,1AC。容易想到用状态压缩DP来做,f[k][i][j]表示当前 i 状态有 k 个串并且串以 j 结尾的最短串。则 f[k][i][rt]=Min{ f[k][i][rt] , f[k][st][r]+len[j]+g[r][j] }。其中状态 i 用位运算表示所包含的具体的串,1010表示包含串2和4。这里要注意转移方程中的rt,要考虑串包含的情况。 1 //STATUS:C++_AC_0MS_324KB 2 #include<stdio.h> 3 #include<stdlib.h> 阅读全文
posted @ 2013-04-10 00:34 zhsl 阅读(512) 评论(0) 推荐(0) 编辑