結果
問題 |
No.90 品物の並び替え
|
ユーザー |
|
提出日時 | 2014-12-26 02:44:21 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 2,095 ms / 5,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 47 ms |
コンパイル使用メモリ | 6,940 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 23:43:26 |
合計ジャッジ時間 | 3,515 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
#!/usr/bin/env python2.7 import sys import itertools def read_n(): return map(int,raw_input().strip().split(" ")) def compute(arr, N): result = 0 for pat in itertools.permutations(range(0, N)): total = 0 for i in range(0, N - 1): for j in range(i + 1, N): total += arr[pat[i]][pat[j]] result = max([total, result]) return result def compute2(scores, left, right): res = 0 for r in right: right2 = list(right) left2 = list(left) right2.remove(r) left2.append(r) childScore = compute2(scores, left2, right2) score = reduce(lambda a,l: a + scores[l][r], left, 0) res = max([score + childScore, res]) return res (N, M) = read_n() arr = [[0 for y in range(0, N)] for x in range(0,N)] for i in range(0,M): (i1, i2, val) = read_n() arr[i1][i2] = val #print compute(arr, N) print compute2(arr, [], range(0, N))