Optimizing iteration over all permutations of a bit array
There's no possibility of an efficient algorithm here, unless you have more information about&nbsp;$T$. $T$&nbsp;might only return true for one input and, in the worst case, you'd have to try all $2^n$ possibilities for that input before finding the right one. Or $T$&nbsp;could return true iff its input contains $n/2$ $1$'s: there are exponentially many such strings and you'd have to try all of them to maximize&nbsp;$f$, since none of those strings is a binary subset of any of the others, so you have no information about the behaviour of&nbsp;$f$ on that set of strings.