Ok I'll have a crack at it, it might be wrong though

Let random numbers

. It doesn't matter how many trials there are, but as long as the difference between the number of times a success (x) is flipped and a failure (y) is flipped is the same, then we will have increased by x-y = n-d to reach n.

Then there are

ways to arrange the probabilities

So

Of course it requires to know 3 things:

1. N

2. D

3. The number of trials.

It also looks quite similar to hypergeometric distribution

thanks for posting this problem :P