Fill the dp matrix horizontally . for contiguous ' X ' increment the value of x , otherwise make it 0
for ( int i = 0 ; i < N ; i ++ ) { x = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( arr [ i ] [ j ] == ' X ' ) x += 1 ; else x = 0 ; dp [ i ] [ j ] . first = x ; } }