计算n*n网格生成树的数目,网格,Python语言: 计算
文章由Byrx.net分享于2019-03-23 09:03:52
计算n*n网格生成树的数目,网格,Python语言: 计算
Python语言: 计算n*n网格生成树的数目from math import cos"""[1] <a href="http://en.wikipedia.org/wiki/Kirchhoff">http://en.wikipedia.org/wiki/Kirchhoff's_theorem[2] <a href="http://www.research.att.com/">http://www.research.att.com/~njas/sequences/A007341[3] Direct Methods for Computing Eigenvalues of the Finite-Difference LaplacianJ. R. KuttlerSIAM Journal on Numerical Analysis, Vol. 11, No. 4 (Sep., 1974), pp. 732-740 """def eigenvalues_of_laplacian(n): ew = [2*(2-cos(i*pi/n)-cos(j*pi/n)) for i in range(n) for j in range(n)] return ewdef num_of_spanning_trees(n): ew = eigenvalues_of_laplacian(n) return reduce(lambda x,y:x*y, ew[1:])/n**2#该片段来自于http://byrx.net
评论关闭