for every j less than i
for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && LIS [ j ] . Count > LIS [ i ] . Count ) { foreach ( int k in LIS [ j ] ) if ( ! LIS [ i ] . Contains ( k ) ) LIS [ i ] . Add ( k ) ; } } LIS [ i ] . Add ( arr [ i ] ) ; }