通用排列
摘要:''' 这个程序不是很有效率,程序中的’if f not in e:‘会产生许多的开销,不是很好,也较难扩展到当L中有重复元素的情况 ''' def permutation_1(L,k): def product2(R,L): R1=[] if R==[[]]: for e in L:R1.appe
阅读全文
组合问题
摘要:def combination_2(L,k): def product2(R,L): R1=[] if R==[[]]: for e in L:R1.append([e]) else: for e in R: for f in L: if f not in e and f >e[-1]: R1.ap
阅读全文
全排列问题
摘要:def permutation_all_1(L): if len(L) <= 1: return [L] T = permutation_all_1(L[1:]) R = [] # 循环方式一: for i in range(len(L)): for t in T: # 循环方式二: # for t
阅读全文
雪花图形绘制
摘要:from turtle import * # 雪花图形 def draw(s, size): for i in s: if i == 's': p.left(60) elif i == 'f': p.forward(size) else: # p.left(-120) p.right(120) de
阅读全文