摘要: KMP算法的next[]数组通俗解释我们在一个母字符串中查找一个子字符串有很多方法。KMP是一种最常见的改进算法,它可以在匹配过程中失配的情况下,有效地多往后面跳几个字符,加快匹配速度。当然我们可以看到这个算法针对的是子串有对称属性,如果有对称属性,那么就需要向前查找是否有可以再次匹配的内容。在KMP算法中有个数组,叫做前缀数组,也有的叫next数组,每一个子串有一个固定的next数组,它记录着字符串匹配过程中失配情况下可以向前多跳几个字符,当然它描述的也是子串的对称程度,程度越高,值越大,当然之前可能出现再匹配的机会就更大。这个next数组的求法是KMP算法的关键,但不是很好理解,我在这里用 阅读全文
posted @ 2014-03-12 22:59 ERKE 阅读(331) 评论(0) 推荐(0) 编辑
摘要: Power StringsTime Limit:3000MSMemory Limit:65536KTotal Submissions:29402Accepted:12296DescriptionGiven two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplicatio 阅读全文
posted @ 2014-03-12 22:01 ERKE 阅读(193) 评论(0) 推荐(0) 编辑
摘要: PalindromeTime Limit:15000MSMemory Limit:65536KTotal Submissions:3280Accepted:1188DescriptionAndy the smart computer science student was attending an algorithms class when the professor asked the students a simple question, "Can you propose an efficient algorithm to find the length of the large 阅读全文
posted @ 2014-03-12 21:10 ERKE 阅读(193) 评论(0) 推荐(0) 编辑
摘要: (转载自)http://blog.csdn.net/hopeztm/article/details/7932245这里描述了一个叫Manacher’sAlgorithm的算法。算法首先将输入字符串S, 转换成一个特殊字符串T,转换的原则就是将S的开头结尾以及每两个相邻的字符之间加入一个特殊的字符,例如#例如: S = “abaaba”, T = “#a#b#a#a#b#a#”.为了找到最长的回文字串,例如我们当前考虑以Ti为回文串中间的元素,如果要找到最长回文字串,我们要从当前的Ti扩展使得Ti-d… Ti+d组成最长回文字串. 这里d其实和 以Ti为中心的回文串长度是一样的. 进一步解释就是 阅读全文
posted @ 2014-03-12 21:09 ERKE 阅读(606) 评论(5) 推荐(0) 编辑
摘要: 最长回文Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6629Accepted Submission(s): 2284Problem Description给出一个只由小写英文字符a,b,c...y,z组成的字符串S,求S中最长回文串的长度.回文就是正反读都是一样的字符串,如aba, abba等Input输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c...y,z组成的字符串S两组case之间由空行隔开(该空行不用处理 阅读全文
posted @ 2014-03-12 20:23 ERKE 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 1297. PalindromeTime limit: 1.0 secondMemory limit: 64 MBThe “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots» security service would have alrea 阅读全文
posted @ 2014-03-12 16:30 ERKE 阅读(239) 评论(0) 推荐(0) 编辑