392. 判断子序列
class Solution {
public:bool isSubsequence(string s, string t) {int m = s.size();int n = t.size();vector<vector<int>> dp(m+1, vector<int>(n+1));for (int i=1; i<=m; i++)for (int j=1; j<=n; j++){if (s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1]+1;else{dp[i][j] = max(dp[i-1][j],dp[i][j-1]);}}return dp[m][n]==m ? true : false;}
};
115. 不同的子序列
class Solution {
public:int numDistinct(string s, string t) {int m = s.size();int n = t.size();vector<vector<unsigned long long>> dp(m+1, vector<unsigned long long>(n+1,0));for (int i=0; i<=m; i++){dp[i][0] = 1;}for (int i=1; i<=m; i++)for (int j=1; j<=n; j++){if (s[i-1]==t[j-1]) dp[i][j] = dp[i-1][j-1] + dp[i-1][j];else dp[i][j] = dp[i-1][j];}return dp[m][n];}
};