結果

問題 No.357 品物の並び替え (Middle)
ユーザー H3PO4H3PO4
提出日時 2020-10-12 09:51:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 200 ms / 5,000 ms
コード長 352 bytes
コンパイル時間 170 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-09-27 23:36:18
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,804 KB
testcase_01 AC 13 ms
7,764 KB
testcase_02 AC 13 ms
7,844 KB
testcase_03 AC 14 ms
7,764 KB
testcase_04 AC 15 ms
7,948 KB
testcase_05 AC 16 ms
7,968 KB
testcase_06 AC 16 ms
7,848 KB
testcase_07 AC 13 ms
7,800 KB
testcase_08 AC 18 ms
7,776 KB
testcase_09 AC 99 ms
8,980 KB
testcase_10 AC 34 ms
8,376 KB
testcase_11 AC 31 ms
8,344 KB
testcase_12 AC 200 ms
9,980 KB
testcase_13 AC 99 ms
8,980 KB
testcase_14 AC 102 ms
9,016 KB
testcase_15 AC 31 ms
8,344 KB
testcase_16 AC 51 ms
8,568 KB
testcase_17 AC 31 ms
8,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
G = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, score = map(int, input().split())
    G[a][b] = score

dp = [0] * (1 << N)
for b in range(1 << N):
    t = tuple(i for i in range(N) if ((b >> i) & 1) == 1)
    for i in t:
        dp[b] = max(dp[b], dp[b - (1 << i)] + sum(G[j][i] for j in t))
print(dp[-1])
0