Length of longest increasing absolute even subsequence | C ++ 14 program for the above approach ; Function to find the longest increasing absolute even subsequence ; Stores length of required subsequence ; Traverse the array ; Traverse prefix of current array element ; Check if the subsequence is LIS and have even absolute difference of adjacent pairs ; Update lis [ ] ; Stores maximum length ; Find the length of longest absolute even subsequence ; Return the maximum length of absolute even subsequence ; Driver code ; Given array arr [ ] and brr [ ] ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void EvenLIS ( int arr [ ] , int n ) { int lis [ n ] ; for ( int i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( abs ( arr [ i ] ) > abs ( arr [ j ] ) && abs ( arr [ i ] ) % 2 == 0 && abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } int maxlen = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxlen = max ( maxlen , lis [ i ] ) ; cout << maxlen << endl ; } int main ( ) { int arr [ ] = { 11 , -22 , 43 , -54 , 66 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; EvenLIS ( arr , N ) ; }