Dp with mixed domains of cnt and bitmask