码迷,mamicode.com
首页 > 其他好文 > 详细

LCS problem using Binary-Search\Rolling hash

时间:2014-12-20 10:26:37      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

One TopCoder article introduces a very interesting alternative solution to Longest Common Sequences problem.

It is based on this statement (http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=stringSearching):

The important point that allows us to use BS is the fact that if the given strings have a common substring of length n, they also have at least one common substring of any length m < n. And if the two strings do not have a common substring of length n they do not have a common substring of any length m > n

So we can start b-search on string length of s1, for s2, since current substr len is fixed, we use rolling-hash to check match. Also, another interesting point to handle collision in a typical BK algorithm: we use double hashing to avoid collision, instead of a O(n) brutal-force string comp mentioned in EPI-300.

LCS problem using Binary-Search\Rolling hash

标签:

原文地址:http://www.cnblogs.com/tonix/p/4175075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!