2019-09-01から1ヶ月間の記事一覧

pythonでCombinationっぽい探索

#!/usr/bin/env python def make_sub(in_li, pre_li): ans_li = [] result_li = [] total = -1 for main_li in in_li: for index in range(len(main_li)): sub_li = main_li[index+1:] total += 1 if sub_li == []: continue result_li.append(sub_li) for s…

pythonで累乗探索

#!/usr/bin/env python def make_ans(ans_li, stocked_li, input_li): total = -1 result_ans_li = [] result_stocked_li = [] for ans in ans_li: total += 1 for index, i in enumerate(input_li): for stocked in stocked_li[total]: if index == stocked…

累乗探索

長さがnのリストが与えられた時に、そのn個から重複を許してk個選び、k個を並べたリストを列挙する。 具体的には[0, 1, 2]のリスト (n=3) , k=3が与えられた時に、[0, 0, 0], [0, 0, 1], [0, 1, 1], ..., [2, 2, 1], [2, 2, 2]の33個のリストを列挙する。 #!…