結果
| 問題 | No.357 品物の並び替え (Middle) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-04-05 00:05:19 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 277 ms / 5,000 ms | 
| コード長 | 715 bytes | 
| コンパイル時間 | 191 ms | 
| コンパイル使用メモリ | 12,672 KB | 
| 実行使用メモリ | 11,264 KB | 
| 最終ジャッジ日時 | 2024-10-04 01:09:30 | 
| 合計ジャッジ時間 | 2,346 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 18 | 
ソースコード
def read_data():
    N, M = map(int, input().split())
    scores = [[0] * N for n in range(N)]
    for m in range(M):
        a, b, c = map(int, input().split())
        scores[a][b] = c
    return N, scores
def solve(N, scores):
    dp = [0] * (1 << N)
    for i in range(1, 1 << N):
        dp[i] = find_max(i, dp, scores, N)
    return dp[-1]
def find_max(used, dp, scores, N):
    record = 0
    for j in range(N):
        if used & (1<<j):
            score = dp[used - (1 << j)]
            sj = scores[j]
            score += sum(sj[b] for b in range(N) if not used & (1<<b))
            if score > record:
                record = score
    return record
N, scores = read_data()
print(solve(N, scores))
            
            
            
        