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;
} 例如:X包含AABB,y包含AACB,我希望我的递归关系跳过c,将AAB作为lCCS,这就是我到目前为止所做的。
发布于 2020-06-23 20:05:40
假设您使用的是std::string,则可以通过字符的erase从字符串中删除字符
std::string A{"AACB"};
std::string copy = A; // make a copy to keep the original
copy.erase(2); // erase character at pos 2
std::cout << copy; // prints AAB如果事先不知道要删除哪个字符,可以尝试循环中的所有字符,并在循环中删除一个字符后调用函数for X和另一个字符串Y。
https://stackoverflow.com/questions/62533265
复制相似问题