hi i am struggling with longest increasing subsequence problem i have figured out the recursive solution and its working but i am unable to apply top down dp to this problem kindly help My code is here:
MAIN : -
int dp[] = new int[arr.length];
System.out.println(LIS(arr,0,Integer.MIN_VALUE,"",dp));
Method Called:
private static int LIS(int[] arr, int i,int prev,String str,int[] dp) {
if(i==arr.length) {
System.out.println(str);
return 0;
}
int ans = 0;
if(dp[i]!=0) return dp[i];
if(arr[i] > prev)
ans = Math.max(ans,LIS(arr, i+1,arr[i],str+arr[i],dp)+1);
ans = Math.max(ans,LIS(arr, i+1, prev,str,dp));
dp[i] = ans;
return dp[i];
}
Kindly highlight my mistake and help with the solution for same