結果

問題 No.90 品物の並び替え
ユーザー 萩3萩3
提出日時 2021-04-30 15:04:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 758 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 76,568 KB
最終ジャッジ日時 2023-09-25 15:28:09
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,460 KB
testcase_01 AC 104 ms
76,540 KB
testcase_02 AC 71 ms
71,232 KB
testcase_03 AC 81 ms
76,548 KB
testcase_04 AC 80 ms
76,396 KB
testcase_05 AC 84 ms
76,568 KB
testcase_06 AC 83 ms
76,560 KB
testcase_07 AC 74 ms
75,596 KB
testcase_08 AC 70 ms
71,312 KB
testcase_09 AC 87 ms
76,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def resolve():
    inp = int2d()
    n,m = inp[0]
    graph = [[0]*n for _ in range(n)]
    for item1,item2,score in inp[1:]:
        graph[item1][item2] = score

    #bit, last vertex
    dp = [[0]*n for _ in range(1<<n)]
    for bit in range(1<<n):
        for vertex in range(n):
            if not(bit & 1<<vertex): continue
            if bit == 1<<vertex: break

            prebit = bit ^ 1<<vertex
            delta = 0
            for shift in range(n):
                if prebit & 1<<shift: delta += graph[shift][vertex]
            
            dp[bit][vertex] = max(dp[prebit]) + delta

    print(max(dp[-1]))

def str1d():return sys.stdin.read().splitlines()
def int2d():return [list(map(int,s.split())) for s in str1d()]

resolve()
0