C++ implementation of LCS