結果

問題 No.357 品物の並び替え (Middle)
ユーザー SI1000-githubSI1000-github
提出日時 2022-10-25 14:16:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 5,000 ms
コード長 926 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 87,380 KB
実行使用メモリ 76,884 KB
最終ジャッジ日時 2023-09-16 12:52:03
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,448 KB
testcase_01 AC 69 ms
71,240 KB
testcase_02 AC 71 ms
75,788 KB
testcase_03 AC 75 ms
75,960 KB
testcase_04 AC 83 ms
76,792 KB
testcase_05 AC 80 ms
76,808 KB
testcase_06 AC 66 ms
71,160 KB
testcase_07 AC 67 ms
71,148 KB
testcase_08 AC 82 ms
76,488 KB
testcase_09 AC 90 ms
76,796 KB
testcase_10 AC 86 ms
76,792 KB
testcase_11 AC 86 ms
76,596 KB
testcase_12 AC 111 ms
76,644 KB
testcase_13 AC 94 ms
76,388 KB
testcase_14 AC 88 ms
76,664 KB
testcase_15 AC 90 ms
76,444 KB
testcase_16 AC 87 ms
76,884 KB
testcase_17 AC 84 ms
76,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-

# import
from sys import stdin, setrecursionlimit
setrecursionlimit(10**8)

def int_map():
    return map(int,input().split())

def int_list():
    return list(map(int,input().split()))

def int_mtx(N):
    x = [list(map(int, stdin.readline().split())) for _ in range(N)]
    return x

def str_mtx(N):
    x = [list(stdin.readline()[:-1]) for _ in range(N)]
    return x

def print_space(l):
    return print(" ".join([str(x) for x in l]))



"""    main code    """

N,M = int_map()

G = [[] for _ in range(N)]

for _ in range(M):
    i,j,c = int_map()
    G[j].append([i,c])

dp = [0 for _ in range(2**N)]

for s in range(2**N):
    for j in range(N):
        if s >> j & 1 == 0:
            cst = 0
            for i,c in G[j]:
                if s >> i & 1 == 1:
                    cst += c                
            dp[s+2**j] = max(dp[s+2**j], dp[s]+cst)

print(dp[2**N-1])
0