From 05164ed65d87e14f92f4809f26eaf514c589292f Mon Sep 17 00:00:00 2001 From: labuladong Date: Wed, 4 Mar 2020 15:19:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=9C=80=E9=95=BF=E5=9B=9E=E6=96=87?= =?UTF-8?q?=E5=AD=90=E5=BA=8F=E5=88=97=E7=9A=84=E5=9B=BE=E7=89=87=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E6=94=B9=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StrategiesForSubsequenceProblem.md | 12 ++++++------ .../{最长回文子序列 => subsequence}/1.jpg | Bin .../{最长回文子序列 => subsequence}/2.jpg | Bin .../{最长回文子序列 => subsequence}/3.jpg | Bin .../{最长回文子序列 => subsequence}/4.jpg | Bin .../{最长回文子序列 => subsequence}/5.jpg | Bin 6 files changed, 6 insertions(+), 6 deletions(-) rename pictures/{最长回文子序列 => subsequence}/1.jpg (100%) rename pictures/{最长回文子序列 => subsequence}/2.jpg (100%) rename pictures/{最长回文子序列 => subsequence}/3.jpg (100%) rename pictures/{最长回文子序列 => subsequence}/4.jpg (100%) rename pictures/{最长回文子序列 => subsequence}/5.jpg (100%) diff --git a/dynamic_programming/StrategiesForSubsequenceProblem.md b/dynamic_programming/StrategiesForSubsequenceProblem.md index 5570f58..d31b274 100644 --- a/dynamic_programming/StrategiesForSubsequenceProblem.md +++ b/dynamic_programming/StrategiesForSubsequenceProblem.md @@ -73,7 +73,7 @@ Now let's talk about the Longest Palindrome Subsequence (LPS) problem to explain We have solve the "Longest Palindrome Substring" problem before. This time, the difficulty is increased by finding the length of the Longest Palindrome Subsequence instead of substring: -![](../pictures/最长回文子序列/1.jpg) +![](../pictures/subsequence/1.jpg) In this question, **we define `dp[i][j]` as the length of the longest palindrome subsequence within the substring `s[i..j]`**. Please remember this definition so as to understand the algorithm. @@ -83,7 +83,7 @@ Specifically, if we want to find `dp[i][j]`, suppose you have already got the re -![](../pictures/最长回文子序列/1.jpg) +![](../pictures/subsequence/1.jpg) The answer is yes! It depends on the characters of `s[i]` and `s[j]`: @@ -91,11 +91,11 @@ The answer is yes! It depends on the characters of `s[i]` and `s[j]`: -![](../pictures/最长回文子序列/2.jpg) +![](../pictures/subsequence/2.jpg) **If they are not equal**, it means that they **cannot appear at the same time** in the longest palindrome subsequence of `s[i..j]`. Therefore, we add them **separately** to `s[i+1..j-1] ` to see which substring produces a longer palindrome subsequence: -![](../pictures/最长回文子序列/3.jpg) +![](../pictures/subsequence/3.jpg) The code of the above two cases can be written like this: @@ -118,9 +118,9 @@ Since `i`must be less than or equal to `j`, for those locations where `i > j`, t In addition, look at the state transition equation we just got. To find `dp[i][j]`, you need to know `dp[i+1][j-1]`, `dp[i+1][j]` and`dp[i][j -1]` these three values. And look at the base case we determined, this is how the DP array looks like after being filled: -![](../pictures/最长回文子序列/4.jpg) +![](../pictures/subsequence/4.jpg) -**In order to guarantee that before each calculation of `dp[i][j]`, the values in the left, down and right direction have been calculated, we can only traverse it diagonally or reversely**:![](../pictures/最长回文子序列/5.jpg) +**In order to guarantee that before each calculation of `dp[i][j]`, the values in the left, down and right direction have been calculated, we can only traverse it diagonally or reversely**:![](../pictures/subsequence/5.jpg) Here I choose to traverse reversely. The code is as follows: diff --git a/pictures/最长回文子序列/1.jpg b/pictures/subsequence/1.jpg similarity index 100% rename from pictures/最长回文子序列/1.jpg rename to pictures/subsequence/1.jpg diff --git a/pictures/最长回文子序列/2.jpg b/pictures/subsequence/2.jpg similarity index 100% rename from pictures/最长回文子序列/2.jpg rename to pictures/subsequence/2.jpg diff --git a/pictures/最长回文子序列/3.jpg b/pictures/subsequence/3.jpg similarity index 100% rename from pictures/最长回文子序列/3.jpg rename to pictures/subsequence/3.jpg diff --git a/pictures/最长回文子序列/4.jpg b/pictures/subsequence/4.jpg similarity index 100% rename from pictures/最长回文子序列/4.jpg rename to pictures/subsequence/4.jpg diff --git a/pictures/最长回文子序列/5.jpg b/pictures/subsequence/5.jpg similarity index 100% rename from pictures/最长回文子序列/5.jpg rename to pictures/subsequence/5.jpg