You are viewing a single comment's thread. Return to all comments →
Recursion with memoization, Here is my CPP code :
const int MAX = 50; int dp[MAX]; int rec(int n){ if(n==1){return dp[1]=1;} else if(n==2){return dp[2]=2;} else if(n==3){return dp[3]=4;} else if(dp[n]!=0){return dp[n];} else {return dp[n]=rec(n-1)+rec(n-2)+rec(n-3);} }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursion: Davis' Staircase
You are viewing a single comment's thread. Return to all comments →
Recursion with memoization, Here is my CPP code :