fork download
  1. //
  2. // main.cpp
  3. // Longest Increasing Subsequence (LIS)
  4. //
  5. // Created by Himanshu on 17/09/21.
  6. //
  7.  
  8. #include <iostream>
  9. using namespace std;
  10. const int N = 8;
  11.  
  12. void LIS (int A[]) {
  13. int LIS[N], sol = 1;
  14.  
  15.  
  16. for (int i=0; i<N; i++) {
  17. LIS[i] = 1;
  18. for (int j=0; j<i; j++) {
  19. if (A[i] > A[j] && LIS[i] < LIS[j]+1) {
  20. LIS[i] = LIS[j] + 1;
  21. }
  22. }
  23. sol = max(sol, LIS[i]);
  24. }
  25.  
  26. cout<<"Length of Longest Increasing Subsequence (LIS) is: "<<sol<<endl;
  27.  
  28. }
  29.  
  30. int main() {
  31. int A[N] = {10,9,2,5,3,7,101,18};
  32. LIS(A);
  33. }
  34.  
Success #stdin #stdout 0.01s 5444KB
stdin
Standard input is empty
stdout
Length of Longest Increasing Subsequence (LIS) is: 4