結果
問題 | No.357 品物の並び替え (Middle) |
ユーザー |
![]() |
提出日時 | 2017-10-11 20:49:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 76 ms / 5,000 ms |
コード長 | 783 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,076 KB |
実行使用メモリ | 71,320 KB |
最終ジャッジ日時 | 2024-11-17 09:45:07 |
合計ジャッジ時間 | 2,230 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
N, M = list(map(int, input().split(' ')))S = []for i in range(N):S.append([0 for _ in range(N)])for i in range(M):f, t, s = list(map(int, input().split(' ')))S[f][t] = s# score for each bit vector expressing that each number is used or notdp = [0 for _ in range(1 << N)]for p in range(1 << N):for i in range(N):# if 'i' is not used yet at p, calculate the score when 'i' is used at pif (p & (1 << i)) == 0:score = dp[p]for j in range(N):if (p & (1 << j)) != 0:score += S[j][i]# update the score when 'i' used at pdp[p | (1 << i)] = max(dp[p | (1 << i)], score)# check the score when all the number is usedprint(dp[(1 << N)-1])