Naxocist

Longest Increasing Subsequence [Bottom Up]

Apr 11th, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int ar[10005], s[10005];
  5.  
  6. int main(){
  7.     int n; scanf("%d", &n);
  8.  
  9.     for(int i=0; i<n; ++i) scanf("%d", &ar[i]);
  10.     int mx = 0;
  11.     s[0] = 1;
  12.     for(int i=1; i<n; ++i){
  13.         int t = 0;
  14.         for(int j=i-1; j>=0; --j){
  15.             if(ar[j] < ar[i]){
  16.                 t = max(t, s[j]);
  17.             }
  18.         }
  19.         s[i] = t+1;
  20.     }
  21.  
  22.     for(int i=0; i<n; ++i) mx = max(mx, s[i]);
  23.     printf("%d", mx);
  24.     return 0;
  25. }
  26.  
Add Comment
Please, Sign In to add comment