def binomialCoef(n, k): C = [0 for x in range(k+1)] C[0] = 1 for i in range(n+1): for j in range(min(i, k),0,-1): C[j] = C[j] + C[j-1] return C[k]