Last active
December 15, 2021 23:22
-
-
Save Parcly-Taxel/986e35b1d13dd2c28f34ff6bb414de5f to your computer and use it in GitHub Desktop.
MSE #4333643
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from math import prod, comb | |
from fractions import Fraction as F | |
N = 12 | |
denom = prod(range(1, 2*N, 2)) | |
print(f"denom = {denom}") | |
states = {(0, N, 0): 1} | |
def dp(k, v): | |
states[k] = states.get(k, 0) + v | |
for n in range(N, -1, -1): | |
for k in range(n//2+1): | |
for d in range(2*N+1): | |
p = states.get((k, n, d), 0) | |
if p == 0: | |
continue | |
del states[(k, n, d)] | |
if k == n == 0: | |
print(f"{d} -> {p*denom}") | |
continue | |
dp((k, n-1, d+1), p*F(n-2*k, comb(2*(n-k), 2))) | |
dp((k+1, n, d+1), p*F(comb(2*n-4*k, 2)-n+2*k, comb(2*(n-k), 2))) | |
dp((k, n-1, d+2), p*F(4*k*(n-2*k), comb(2*(n-k), 2))) | |
dp((k-1, n-2, d+3), p*F(comb(2*k, 2), comb(2*(n-k), 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment