小编Vai*_*hra的帖子

无序逃生-Google Foobar 2020 未通过测试用例

代码运行良好,并在 python 编译器中在线执行,但在 Google Foobar 中的所有测试用例都失败了

from math import factorial
from collections import Counter
from fractions import gcd

def cycle_count(c, n):
    cc=factorial(n)
    for a, b in Counter(c).items():
        cc//=(a**b)*factorial(b)
    return cc        

def cycle_partitions(n, i=1):
    yield [n]
    for i in range(i, n//2+1):
        for p in cycle_partitions(n-i, i):
            yield [i]+p

def solution(w, h, s):    
    grid=0
    for cpw in cycle_partitions(w):
        for cph in cycle_partitions(h):            
            m=cycle_count(cpw, w)*cycle_count(cph, h)
            grid+=m*(s**sum([sum([gcd(i, j) for i in cpw]) for j in cph]))
    return grid//(factorial(w)*factorial(h))
Run Code Online (Sandbox Code Playgroud)

看看这个要执行的代码。希望得到建议!!!

python python-2.7 data-structures python-3.x

2
推荐指数
1
解决办法
2368
查看次数

标签 统计

data-structures ×1

python ×1

python-2.7 ×1

python-3.x ×1