Longest increasing subsequence doubt

my code is giving wrong answer for lis-top down approach please help code:
#include
using namespace std;
int lis(int *arr,int i,in
t j,int n)
{
if( arr[j] <arr[i] || j==n)
{
return 0;
}

int inc=1+lis(arr,i,j+1,n);
int ex=lis(arr,i,j+1,n);
int x=max(inc,ex);
return x;

}
int main()
{
int n;
cin>>n;
int a[1000];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<lis(a,0,0,n);
}

@khushi91200 hey this logic will not work here as you have to check previous all eleements of current element as is is increasing subsequence.Here is pseudo code for that:
public int LIS(int[] arr) {
return LISLength(arr, Integer.MIN_VALUE, 0);
}

public int LISLength(int[] arr, int prev, int current) {
    if (current == arr.length) {
        return 0;
    }
    int include = 0;
    if (arr[current] > prev) {
        include = 1 + LISLength(arr, arr[current], current + 1);
    }
    int exclude = LISLength(arr, prev, current + 1);
    return Math.max(include, exclude);
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.