結果

問題 No.357 品物の並び替え (Middle)
ユーザー moharan627moharan627
提出日時 2021-08-10 17:27:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 1,133 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 80,520 KB
最終ジャッジ日時 2023-10-24 01:59:58
合計ジャッジ時間 3,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
80,292 KB
testcase_01 AC 85 ms
74,416 KB
testcase_02 AC 101 ms
79,736 KB
testcase_03 AC 99 ms
79,732 KB
testcase_04 AC 106 ms
80,284 KB
testcase_05 AC 105 ms
80,252 KB
testcase_06 AC 85 ms
75,548 KB
testcase_07 AC 83 ms
74,420 KB
testcase_08 AC 111 ms
80,156 KB
testcase_09 AC 125 ms
80,516 KB
testcase_10 AC 115 ms
80,292 KB
testcase_11 AC 112 ms
80,208 KB
testcase_12 AC 132 ms
80,344 KB
testcase_13 AC 127 ms
80,508 KB
testcase_14 AC 124 ms
80,520 KB
testcase_15 AC 110 ms
80,212 KB
testcase_16 AC 118 ms
80,332 KB
testcase_17 AC 111 ms
80,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
#from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    N,M = MI()
    Score = [[0]*N for _ in range(N)]
    for _ in range(M):
        item1,item2,s = MI()
        Score[item1][item2] = s
    DP = [-INF for _ in range(2 ** N)]
    DP[0] = 0
    from pprint import pprint
    for S in range(2 ** N):
        if S == 0:
            for n in range(N):
                DP[S | (1 << n)] = 0
            continue
        for t in range(N):
            if S >> t & 1:continue
            Tmp = 0
            for s in range(N):
                if S >> s & 1:
                    Tmp += Score[s][t]
            DP[S|(1 << t)] = max(DP[S] + Tmp,DP[S|(1 << t)])
    #print(DP)
    print(DP[S])
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0