結果

問題 No.357 品物の並び替え (Middle)
ユーザー roarisroaris
提出日時 2019-10-29 12:43:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 503 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 76,492 KB
最終ジャッジ日時 2023-10-12 23:20:04
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,020 KB
testcase_01 AC 75 ms
70,920 KB
testcase_02 AC 76 ms
75,984 KB
testcase_03 AC 78 ms
75,568 KB
testcase_04 AC 82 ms
76,028 KB
testcase_05 AC 83 ms
75,892 KB
testcase_06 AC 74 ms
71,216 KB
testcase_07 AC 72 ms
71,316 KB
testcase_08 AC 88 ms
76,432 KB
testcase_09 AC 91 ms
76,208 KB
testcase_10 AC 87 ms
76,348 KB
testcase_11 AC 97 ms
76,492 KB
testcase_12 AC 105 ms
76,096 KB
testcase_13 AC 95 ms
76,440 KB
testcase_14 AC 93 ms
76,204 KB
testcase_15 AC 94 ms
76,360 KB
testcase_16 AC 91 ms
76,448 KB
testcase_17 AC 85 ms
76,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
scores = [[] for _ in range(N)]

for _ in range(M):
    item1, item2, score = map(int, input().split())
    scores[item2].append((item1, score))

dp = [0] * (1<<N)

for S in range((1<<N)-2, -1, -1):
    for n in range(N):
        if not (S>>n)&1:
            add = 0
            
            for prev, score in scores[n]:
                if (S>>prev)&1:
                    add += score
                    
            dp[S] = max(dp[S], dp[S|(1<<n)]+add)

print(dp[0])
0