//
// main.cpp
// Longest Increasing Subsequence (LIS)
//
// Created by Himanshu on 17/09/21.
//
#include <iostream>
using namespace std;
const int N = 8;
void LIS (int A[]) {
int LIS[N], sol = 1;
for (int i=0; i<N; i++) {
LIS[i] = 1;
for (int j=0; j<i; j++) {
if (A[i] > A[j] && LIS[i] < LIS[j]+1) {
LIS[i] = LIS[j] + 1;
}
}
sol = max(sol, LIS[i]);
}
cout<<"Length of Longest Increasing Subsequence (LIS) is: "<<sol<<endl;
}
int main() {
int A[N] = {10,9,2,5,3,7,101,18};
LIS(A);
}
Ly8KLy8gIG1haW4uY3BwCi8vICBMb25nZXN0IEluY3JlYXNpbmcgU3Vic2VxdWVuY2UgKExJUykKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMTcvMDkvMjEuCi8vCgojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gODsKCnZvaWQgTElTIChpbnQgQVtdKSB7CiAgICBpbnQgTElTW05dLCBzb2wgPSAxOwogICAgCiAgICAKICAgIGZvciAoaW50IGk9MDsgaTxOOyBpKyspIHsKICAgICAgICBMSVNbaV0gPSAxOwogICAgICAgIGZvciAoaW50IGo9MDsgajxpOyBqKyspIHsKICAgICAgICAgICAgaWYgKEFbaV0gPiBBW2pdICYmIExJU1tpXSA8IExJU1tqXSsxKSB7CiAgICAgICAgICAgICAgICBMSVNbaV0gPSBMSVNbal0gKyAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNvbCA9IG1heChzb2wsIExJU1tpXSk7CiAgICB9CiAgICAKICAgIGNvdXQ8PCJMZW5ndGggb2YgTG9uZ2VzdCBJbmNyZWFzaW5nIFN1YnNlcXVlbmNlIChMSVMpIGlzOiAiPDxzb2w8PGVuZGw7CiAgICAKfQogCmludCBtYWluKCkgewogICAgaW50IEFbTl0gPSB7MTAsOSwyLDUsMyw3LDEwMSwxOH07CiAgICBMSVMoQSk7Cn0K