摘要:
class Stack(object): """ A class to hold arguements and state data. """ def __init__(self,**kwargs): self.__dict__.update(kwargs) def __repr__(self): extra = "|i:%s"%self.i if hasattr(self,'i') else '' return "n:%s|stage:%s%s"%(self.n 阅读全文
摘要:
def hanoi_recur(n,reverse=True): if n==1: return 1,1 possible=[] iter_range=range(n-1,0,-1) if reverse else range(1,n) for i in iter_range: _, min_v = hanoi_recur(n-i,reverse) possible.append((i,2*min_v+2**i-1)) return min(possible,key=lambda x:x[1])如上所示,hanoi_rec... 阅读全文