Seongbeom Park c4efc8d7d1 Using Burnside lemma
Need to implement counting the cycles for each combination

* Reference: https://youtu.be/D0d9bYZ_qDY
2022-03-20 07:38:10 +09:00

27 lines
526 B
Python

import math
def solution(w, h, s):
return str(sum([s**cycle for cycle in generate_cycles(w, h)])/(math.factorial(w)*math.factorial(h)))
def generate_cycles(w, h):
yield 1
tests = [
([2, 3, 4], '430'),
([2, 2, 2], '7'),
([1, 1, 2], '2'),
([1, 1, 3], '3'),
([2, 1, 2], '3'),
([1, 2, 2], '3'),
([3, 1, 2], '4'),
([1, 3, 2], '4'),
([2, 3, 2], '13'),
]
for i, o in tests:
result = solution(*i)
print (i, result == o, result, o)