Skip to content

Instantly share code, notes, and snippets.

@ygabo
Created June 11, 2013 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ygabo/5755075 to your computer and use it in GitHub Desktop.
Save ygabo/5755075 to your computer and use it in GitHub Desktop.
Longest Commong Substring (Length only)
void main(){
// 5-choose-3
std::size_t n =184;
std::size_t k = 3;
std::string s = "hello";
std::string s2 = "llo";
std::vector<std::vector<int>> lcs(s.length()+1, std::vector<int>(s2.length()+1));
for( int i = 0; i < lcs.size(); ++i ){
for( int j = 0; j < lcs[i].size(); ++j ){
if( i == 0 || j == 0 ) lcs[i][j] = 0;
else if( s[i] == s2[j] ){
lcs[i][j] = lcs[i-1][j-1] + 1;
}
}
}
for( auto i : lcs ){
for( auto j : i ){
std::cout << j << " ";
}
std::cout << std::endl;
}
std::cout << lcs.back().back() << std::endl;
std::cin.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment