結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
htkb
|
| 提出日時 | 2019-02-11 16:31:56 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 5,000 ms |
| コード長 | 545 bytes |
| コンパイル時間 | 89 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-07-18 12:35:58 |
| 合計ジャッジ時間 | 895 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
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])
htkb