第21222题 单选题
动态规划求解最长公共子序列长度的代码中,横线处应填入哪项

下面程序使用动态规划求两个字符串的最长公共子序列(LCS)长度,横线处应填入的是( )。

#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int lcs_len(const string &a, const string &b) {
    int n = (int)a.size(), m = (int)b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                ________; // 在此处填入选项
    return dp[n][m];
}
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析