Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- using namespace std;
- int _LIS(int arr[],int n,int *max_ref){
- if(n==1)
- return 1;
- int res=0,max_ending_here=0;
- for(int i=1;i<n;i++){
- res=_LIS(arr,i,max_ref);
- if(arr[i-1]<arr[n-1] && res+1 >max_ending_here)
- max_ending_here=res+1;
- }
- if(*max_ref<max_ending_here)
- *max_ref=max_ending_here;
- return max_ending_here;
- }
- int LIS(int arr[],int n){
- if(n==0)
- return n;
- int max=1;
- _LIS(arr,n,&max);
- return max;
- }
- int main(){
- int n=8;
- int arr[] = {10,22,9, 33, 21, 50, 41, 60 };
- cout<<LIS(arr,n);
- return 0;
- }
Add Comment
Please, Sign In to add comment