Maximum length sub - sequence of ( 0. . 1. .0 . .1 . . )
for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) { dp [ 3 , i ] = Math . Max ( dp [ 3 , i - 1 ] + 1 , Math . Max ( dp [ 2 , i - 1 ] + 1 , Math . Max ( dp [ 1 , i - 1 ] + 1 , dp [ 0 , i - 1 ] + 1 ) ) ) ; } else dp [ 3 , i ] = dp [ 3 , i - 1 ] ; }