結果
問題 | No.90 品物の並び替え |
ユーザー | kroton |
提出日時 | 2014-12-07 20:47:47 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 15 ms / 5,000 ms |
コード長 | 475 bytes |
コンパイル時間 | 576 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-06-11 17:05:24 |
合計ジャッジ時間 | 774 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
dp = [-1] * (1 << 10) score = [0] * 1000 N, M = map(int, raw_input().split()) for t in xrange(M): a, b, c = map(int, raw_input().split()) score[a * N + b] = c def solve(m): if dp[m] != -1: return dp[m] res = 0 for i in xrange(0, N): if (m >> i) & 1 == 0: tmp = 0 for j in xrange(0, N): if (m >> j) & 1 == 1: tmp += score[i * N + j] res = max(res, tmp + solve(m | (1 << i))) dp[m] = res return res print solve(0)