結果

問題 No.90 品物の並び替え
コンテスト
ユーザー maatanbeta
提出日時 2017-04-27 15:48:02
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 936 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 333 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2026-04-04 05:54:28
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from copy import deepcopy

N, M = map(int, input().split())
item1 = [0] * M
item2 = [0] * M
score = [0] * M
sheat = []
max_score = 0

for p in range(N):
    l = []
    for q in range(N):
        l.append(0)
    sheat.append(l)

for i in range(M):
    item1[i], item2[i], score[i] = map(int, input().split())
    sheat[item1[i]][item2[i]] = score[i]

dic = {}


def dp(check):
    global dic
    if len(check) == 0:
        return 0
    elif len(check) == 1:
        return 0
    elif tuple(check) in dic:
        return dic[tuple(check)]
    else:
        tempmax = 0
        for i in check:
            temp = deepcopy(check)
            temp.remove(i)
            temp2 = 0
            for p in temp:
                temp2 += sheat[p][i]
            temp2 += dp(temp)
            if tempmax < temp2:
                tempmax = temp2
        dic[tuple(check)] = tempmax
        return tempmax


l = [i for i in range(N)]

print(dp(l))
0