Given binary string of length n with k bit sets, how many permutations have x consecutive ones and no y consecutive ones where y > x

722 Views Asked by At

Not sure if this is possible to calculate in an easy way but given binary string of length n with k bit sets, how many permutations have x consecutive ones and no y consecutive ones where y > x

An example to make sense of what I mean

n = 5, k = 3 we have following permutations

00111 01011 01101 01110 10011 10101 10110 11001 11010 11100

In this example we have for x = 3

00111

01110

11100

x = 2

01011 01101 10011 10110 11001 11010

x = 1

10101

So answer is for x = 3 we have 3 ways, x = 2 we have 6 ways and x = 1 we have 1 way. Can this be expressed within a formula?

Hope I explained it well enough. Cheers