From cf9fed5b11a9c33c838d3114de8a123701b7e27d Mon Sep 17 00:00:00 2001 From: Akshat Sharma <83509798+akshatsh0610@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:14:03 +0530 Subject: [PATCH] Update longest_increasing_subsequence.cpp Added Memoization method to longest_increasing_subsequence.cpp --- .../longest_increasing_subsequence.cpp | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/algorithms/dynamic-programming/longest_increasing_subsequence.cpp b/algorithms/dynamic-programming/longest_increasing_subsequence.cpp index 55073440..db002ccb 100644 --- a/algorithms/dynamic-programming/longest_increasing_subsequence.cpp +++ b/algorithms/dynamic-programming/longest_increasing_subsequence.cpp @@ -1,6 +1,7 @@ #include +#include using namespace std; -int longestIncreasingSubsequence(int A[],int size){ +int longestIncreasingSubsequenceThroughTabulation(int A[],int size){ int dp[size]; for(int i=0;i>&dp){ + if(idx>=size) + return 0; + if(dp[idx][prev+1]!=-1){ + return dp[idx][prev+1]; + } + int choise1=0; + int choise2=0; + if(prev==-1){ + choise1=1+longestIncreasingSubsequenceThroughMemoization(A,idx+1,idx,size); + } + if(A[prev] "<>dp(size,vector(size,-1)); + cout<<"Memoization -> "<