Double Sequence
1540t Can Convert
Given two string S and T, determine if S can be changed to T by deleting some letters (including 0 letter)
Statement: 從s前i個組成的string是否可以轉成t前j個組成的string
Func: if s[i] == t[j] -> dp[i][j] |= dp[i-1][j-1], else dp[i][j] |= dp[i-1][j];
Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.
Example Given S = "rabbbit", T = "rabbit", return 3.
State: f[i][j]表示S中前i個子串可以選出T前j個子串的個數
Func: f[i][j] = f[i-1][j-1]+f[i-1][j] if S[i-1]==T[j-1]
else f[i][j] = f[i-1][j]
Init: f[i][0] = 1, f[0][j] = 0
97. InterLeaving String
Given three strings: s1, s2, s3, determine whether s3 is formed by the interleaving of s1 and s2.
State: f[i][j]表示s1前i個字符和s2前j個字符可以組成s3前i+j個字符
Func: f[i-1][j] && s1[i-1]==s3[i+j-1] ||
f[i][j-1] && s2[j-1]==s3[i+j-1]
Init: f[i][0] = s1[0...i-1] = s3[0...i-1], f[0][j] = s2[0...j-1] = s3[0...j-1]
Ans: f[m][n]
Last updated
Was this helpful?