#include<bits/stdc++.h>
using namespace std;
int longestis(int a[], int n, int *mx)
{
if(n == 1)
return 1;
int res, mx_end = 1;
for(int i=1;i<n;i++)
{
res = longestis(a, i, mx);
if(a[i-1] < a[n-1] && res+1 > mx_end)
mx_end = res + 1;
}
if(*mx < mx_end)
*mx = mx_end;
return mx_end;
}
int lis(int a[], int n)
{
int mx = 1;
longestis(a, n, &mx);
return mx;
}
int main()
{
int n, i;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "\nEnter Array Element :: \n";
for(i=0;i<n;i++)
cin >> a[i];
cout << "\nLongest Increasing Subsequence Size :: " << lis(a, n) << "\n";
return 0;
}
Comments
Post a Comment