Hello!,
New to dynamic programming
Following this approach from a certain period of time
Recursive Algorithm ---> Memoize ---> Accept
But stuck in this problem, although got the solution using maps and recursion
But want to know can we memoize this particular piece of code
int n;
bool f(int i, string s, string &t, vector<string>& w){
if(i>=n || s.length()>t.length()) return false;
s+=w[i];
if(s==t) return true;
for(int j=0;j<n;++j){
if(f(j,s,t,w)) return true;
}
return false;
}
bool wordBreak(string s, vector<string>& wordDict) {
n=wordDict.size();
string temp="";
for(int i=0;i<n;++i){
if(f(i,temp,s,wordDict)) return true;
}
return false;
}Question : [https://leetcode.com/problems/word-break/]
Help
Thanks in advance!!.