dp [ i ] [ j ] be the longest subsequence of a [ 0. . . i ] with first j parts
int dp [ 4 ] [ n ] ; memset ( dp , 0 , sizeof ( dp [ 0 ] [ 0 ] * 4 * n ) ) ; if ( arr [ 0 ] == 0 ) dp [ 0 ] [ 0 ] = 1 ; else dp [ 1 ] [ 0 ] = 1 ;