Initialize dp array , where dp [ i ] [ j ] stores the number of alternating strings starts with i and having j elements .
int [ ] [ ] dp = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { dp [ i ] [ j ] = 0 ; } }