My solution is like this:
Code: Select all
P = population
Q = Sum of populations
C = child[root][child_index]
Solve(root, child_index, x = Q[0..child_index-1]) = Solve(root, child_index+1, x + P[C]) * Solve(C, 0, 0) * Choose(P[C], P[root] - x - 1)

Moderator: Board moderators
Code: Select all
P = population
Q = Sum of populations
C = child[root][child_index]
Solve(root, child_index, x = Q[0..child_index-1]) = Solve(root, child_index+1, x + P[C]) * Solve(C, 0, 0) * Choose(P[C], P[root] - x - 1)
That's what I used.krijger wrote:The following was my first attempt, but timed out:
* If k>2, then choose(n,x_1,x_2,...,x_k)=choose(n,x_1,n-x_1)*choose(n-x_1,x_2,....x_k)