problem:https://leetcode.com/problems/distinct-subsequences/
字符匹配类型题目。
class Solution { public: vector<vector<int>> dp; int numDistinct(string& s, string& t, int i, int j) { if(j == t.size()) return 1; if(i == s.size()) return 0; if(dp[i][j] != -1) return dp[i][j]; if(s[i] == t[j]) { return dp[i][j] = numDistinct(s, t, i + 1, j + 1) + numDistinct(s, t, i + 1, j); } else { return dp[i][j] = numDistinct(s, t, i + 1, j); } } int numDistinct(string s, string t) { dp.resize(s.size(), vector<int>(t.size(), -1)); return numDistinct(s, t, 0, 0); } };