結果

問題 No.90 品物の並び替え
ユーザー nisizawa
提出日時 2017-12-11 09:03:33
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 526 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-30 11:34:32
合計ジャッジ時間 1,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())

score = [[0] * n for i in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    score[a][b] = c

comb = (1 << n) - 1
dp = [0] * (comb + 1)
for c in range(1, comb):
    for i in range(n):
        f1 = 1 << i
        if not c & f1 == 0:
            continue
        cf = c | f1
        s = dp[c]
        for j in range(n):
            f2 = 1 << j
            if c & f2 == 0:
                continue
            s += score[j][i]
        dp[cf] = max(s, dp[cf])

print(dp[-1])
0