How can we calculate longest common substring with one atmost one skip?

杀马特。学长 韩版系。学妹 提交于 2020-06-29 04:45:08

问题


Here is the code: I am able to find the longest common substring but I would like to find the longest common substring with at most one skip ?

#include <iostream> 

using namespace std; 

string X,Y; 

int lcs(int i, int j, int count) 
{ 

    if (i == 0 || j == 0) 
        return count; 
    
    if (X[i-1] == Y[j-1]) { 
        count = lcs(i - 1, j - 1, count + 1); 
    } 
    count = max(count, max(lcs( i, j - 1, 0), lcs( i - 1, j, 0))); 
    return count; 
} 



int main() 
{      
    int n,m; 

    X = "AACBkkkk"; 
    Y = "AABDkkkks"; 
    n=X.size(); 
    m=Y.size(); 
    cout<<lcs(n,m,0); 

    return 0; 
} 

来源:https://stackoverflow.com/questions/62495298/how-can-we-calculate-longest-common-substring-with-one-atmost-one-skip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!