[动态规划] leetcode 115 Distinct Subsequences
Posted fish1996
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[动态规划] leetcode 115 Distinct Subsequences相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
动态规划之115 Distinct Subsequences
[LeetCode]题解(python):115-Distinct Subsequences