If this arrangement is not possible then don 't calculate further
if ( temp != Integer . MAX_VALUE ) { ans = Math . min ( ans , temp + ( ones * zeroes ) ) ; } } return dp [ start ] [ bucket ] = ans ; }