Longest Common Subsequence
Problem:
It is common sense that the max LCS will be the max of dp[i - 1][j] and dp[i][j-1]. What else choice do we have!
思路:
匹配DP画矩阵
state: dp[i][j], 第一个string 前i个和第二个string 前j个的LCS.
transition: if(A[i-1]==B[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1])
Given two strings, find the longest common subsequence (LCS).
Your code should return the length of LCS.
Clarification
What's the definition of Longest Common Subsequence?
Example
It is common sense that the max LCS will be the max of dp[i - 1][j] and dp[i][j-1]. What else choice do we have!
思路:
匹配DP画矩阵
state: dp[i][j], 第一个string 前i个和第二个string 前j个的LCS.
transition: if(A[i-1]==B[j-1]) dp[i][j]=dp[i-1][j-1]+1; else dp[i][j]=max(dp[i-1][j],dp[i][j-1])
评论
发表评论