标签:http color 规划 ble lse vector 动态规划 code enc
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); } };
[动态规划] leetcode 115 Distinct Subsequences
标签:http color 规划 ble lse vector 动态规划 code enc
原文地址:https://www.cnblogs.com/fish1996/p/11330015.html