fucking-algorithm icon indicating copy to clipboard operation
fucking-algorithm copied to clipboard

对动态规划发动降维打击 :: labuladong的算法小抄

Open utterances-bot opened this issue 4 years ago • 1 comments

对动态规划发动降维打击 :: labuladong的算法小抄

https://labuladong.gitee.io/algo/3/22/57/

utterances-bot avatar Jul 05 '21 04:07 utterances-bot

请问,在 对动态规划发动降维打击( https://labuladong.gitee.io/algo/3/22/57/ )中的关于一维的dp数组代表的原二维dp数组中的解释(如下图),这里怎么看出一个是外层、一个是内层的?还有就是dp[j - 1]在代码中有两处,那问题2中指的是哪一个呢? 疑问

for (int i = n - 2; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
        // 在这里,一维 dp 数组中的数是什么?
        if (s[i] == s[j])
            dp[j] = dp[j - 1] + 2;
        else
            dp[j] = max(dp[j], dp[j - 1]);
    }
}

longlongqin avatar Jul 05 '21 04:07 longlongqin