Longest Increasing Odd Even Subsequence | function to find the longest increasing odd even subsequence ; lioes [ i ] stores longest increasing odd even subsequence ending at arr [ i ] ; to store the length of longest increasing odd even subsequence ; Initialize LIOES values for all indexes ; Compute optimized LIOES values in bottom up manner ; Pick maximum of all LIOES values ; required maximum length ; Driver Code
< ? php function longOddEvenIncSeq ( & $ arr , $ n ) { $ lioes = array_fill ( 0 , $ n , NULL ) ; $ maxLen = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ lioes [ $ i ] = 1 ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) for ( $ j = 0 ; $ j < $ i ; $ j ++ ) if ( $ arr [ $ i ] > $ arr [ $ j ] && ( $ arr [ $ i ] + $ arr [ $ j ] ) % 2 != 0 && $ lioes [ $ i ] < $ lioes [ $ j ] + 1 ) $ lioes [ $ i ] = $ lioes [ $ j ] + 1 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) if ( $ maxLen < $ lioes [ $ i ] ) $ maxLen = $ lioes [ $ i ] ; return $ maxLen ; } $ arr = array ( 1 , 12 , 2 , 22 , 5 , 30 , 31 , 14 , 17 , 11 ) ; $ n = sizeof ( $ arr ) ; echo " Longest ▁ Increasing ▁ Odd ▁ Even ▁ " . " Subsequence : ▁ " . longOddEvenIncSeq ( $ arr , $ n ) ; ? >