abc 165 C - Many Requirements (python)
今回の反省と学び
19C10 ≒ 46000 くらいの全探索が通ること。(総数が19C10 なのは分かっていた)
重複組み合わせの itertools が用意されていること。
itertools 使うときは順列の要素がデフォルト時は 0 から始まるので注意
次は5完する。
import sys input = sys.stdin.readline n,m,q = map(int,input().split()) chk = [] for i in range(q): a = [int(i) for i in input().split()] chk.append(a) ans = 0 import itertools for i in itertools.combinations_with_replacement(range(1, m+1), n): dd = 0 for j in chk: a,b,c,d = j if i[a-1] + c == i[b-1]: dd += d ans = max(dd,ans) print(ans)