leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0115.cpp (609B)
0 class Solution {
1 static int dp[1001][1001];
3 static int rec(const string &s, const string &t, int check, int goal) {
4 if (goal == size(t)) return 1;
5 if (check == size(s)) return 0;
6 if (dp[check][goal] != -1) return dp[check][goal];
8 int res = rec(s, t, check + 1, goal);
9 if (s[check] == t[goal]) res += rec(s, t, check + 1, goal + 1);
10 return dp[check][goal] = res;
11 }
13 public:
14 int numDistinct(const string &s, const string &t) const {
15 memset(dp, 0xFF, sizeof(dp));
16 return rec(s, t, 0, 0);
17 }
18 };
20 int Solution::dp[1001][1001];