全排列

2018-07-02  本文已影响0人  领悟悟悟
from copy import copy

f  = open('全排列.txt', 'w', encoding='utf-8')
count = 0


def func_all(num=0, ls=[], tag=3):
    ls.append(num)
    if len(ls)-1 == tag:
        print(ls[1:], file=f)
        global count
        count += 1
        return

    for i in range(1, tag+1):
        if i not in ls:
            func_all(i, copy(ls),tag)


func_all(tag=2)
print(count)
上一篇 下一篇

猜你喜欢

热点阅读