結果

問題 No.357 品物の並び替え (Middle)
ユーザー Nikkuniku029Nikkuniku029
提出日時 2021-08-24 21:43:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 981 ms / 5,000 ms
コード長 442 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-04-27 09:39:29
合計ジャッジ時間 4,109 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
10,880 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 32 ms
10,752 KB
testcase_03 AC 33 ms
10,752 KB
testcase_04 AC 35 ms
10,752 KB
testcase_05 AC 36 ms
10,752 KB
testcase_06 AC 30 ms
10,752 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 42 ms
10,752 KB
testcase_09 AC 436 ms
11,008 KB
testcase_10 AC 103 ms
10,880 KB
testcase_11 AC 109 ms
10,752 KB
testcase_12 AC 981 ms
11,520 KB
testcase_13 AC 452 ms
11,136 KB
testcase_14 AC 448 ms
11,008 KB
testcase_15 AC 106 ms
10,752 KB
testcase_16 AC 209 ms
10,880 KB
testcase_17 AC 108 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
score = [[0]*n for _ in range(n)]
for _ in range(m):
    a, b, s = map(int, input().split())
    score[a][b] = s
dp = [0]*(1 << n)
for s in range(1 << n):
    for v in range(n):
        tmp=0
        for u in range(n):
            if (s >> u) & 1 and (s >> v) & 1 == 0:
                tmp+=score[u][v]
        if dp[s]+tmp >= dp[s | (1 << v)]:
            dp[s | (1 << v)] = dp[s]+tmp

print(dp[(1 << n)-1])
0