結果

問題 No.90 品物の並び替え
ユーザー htkbhtkb
提出日時 2019-02-11 16:31:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 545 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2023-09-25 15:57:27
合計ジャッジ時間 1,370 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,904 KB
testcase_01 AC 17 ms
7,864 KB
testcase_02 AC 15 ms
7,808 KB
testcase_03 AC 17 ms
7,864 KB
testcase_04 AC 17 ms
7,852 KB
testcase_05 AC 18 ms
7,936 KB
testcase_06 AC 17 ms
7,808 KB
testcase_07 AC 16 ms
7,788 KB
testcase_08 AC 16 ms
7,976 KB
testcase_09 AC 20 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [0]*(2**N)

for bitset in range(2**N):
    current_score = dp[bitset]
    bit_1_list = [i for i in range(N) if bitset & 2**i]

    for bit_0 in range(N):
        if 2**bit_0 & bitset:
            continue
        new_score = current_score + sum(score[bit_1][bit_0] for bit_1 in bit_1_list)
        if new_score > dp[bitset | 2**bit_0]:
            dp[bitset | 2**bit_0] = new_score

print(dp[-1])
0