python python中的perm算法,带有一个slot对象。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python中的perm算法,带有一个slot对象。相关的知识,希望对你有一定的参考价值。
#permutation distinct element algorithm
#number of permutations:
import math
def perm_num(n):
return math.factorial(n)//math.factorial(n-n)
#number of appearances in each slot
def slot_events(k):
return perm_num(k)//k
def permutations(lst):
perm_template = []
perms = []
slot_max = slot_events(len(lst))
max_perms = perm_num(len(lst))
slot_counts = {x:[] for x in range(len(lst))}
####
class slot(object):
def __init__(self, value=None):
self.value = value
self.memo = []
if self.value:
self.memo.append(value)
def __repr__(self):
return str(self.value)
def __str__(self):
return str(self.value)
def change_val(self, other):
self.memo.append(other)
self.value = other
以上是关于python python中的perm算法,带有一个slot对象。的主要内容,如果未能解决你的问题,请参考以下文章
为啥这个算法在 python 中的运行速度比在 C++ 中快得多?
python 全排列
全排列问题的递归算法(Perm)
分享《Python学习手册(第4版)》高清中文PDF+高清英文PDF+源代码+《算法图解》PDF代码
是否可以在网络上的python中集成机器学习算法
带有大熊猫数据框的python代码很慢