Advertisement
istinishat

longest Increasing subsequence

Mar 17th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. http: // .  lightoj.com/article_show.php?article=1000&language=english&type=pdf
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define si(n) scanf("%d",&n)
  7. #define MAX 100005
  8. #define INF 0x3f3f3f3f
  9.  
  10. int arr[MAX],t[MAX],l[MAX];
  11.  
  12. int main()
  13. {
  14.     //freopen("input.txt","r",stdin);
  15.     int i,j,n;
  16.     si(n);
  17.     for(i=0;i<n;i++)si(arr[i]);
  18.  
  19.     memset(t,INF,sizeof(t));
  20.     int mx_len=0;
  21.  
  22.     for(i=0;i<n;i++){
  23.         int lo=0,hi=mx_len+1;
  24.         while(hi-lo>1){
  25.             int mid=(hi+lo)/2;
  26.             if(t[mid]>=arr[i])hi=mid;
  27.             else lo=mid;
  28.         }
  29.         lo++;
  30.         t[lo]=arr[i];
  31.         l[i]=lo;
  32.         mx_len=max(mx_len,lo);
  33.     }
  34.  
  35.     printf("%d\n",mx_len);
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement