結果
問題 | No.90 品物の並び替え |
ユーザー | tookunn_1213 |
提出日時 | 2016-06-28 23:01:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 788 ms / 5,000 ms |
コード長 | 913 bytes |
コンパイル時間 | 427 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 179,284 KB |
最終ジャッジ日時 | 2024-04-20 03:12:48 |
合計ジャッジ時間 | 2,379 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
53,740 KB |
testcase_01 | AC | 142 ms
84,412 KB |
testcase_02 | AC | 34 ms
54,152 KB |
testcase_03 | AC | 86 ms
76,748 KB |
testcase_04 | AC | 83 ms
76,852 KB |
testcase_05 | AC | 156 ms
84,248 KB |
testcase_06 | AC | 149 ms
84,356 KB |
testcase_07 | AC | 64 ms
70,712 KB |
testcase_08 | AC | 35 ms
53,440 KB |
testcase_09 | AC | 788 ms
179,284 KB |
ソースコード
class Main: N,M = 0,0 dp = [{}] score = [[]] used = [] def __init__(self): pass def dfs(self,n,s): if n == self.N: lis = list(str(s)) ret = 0 for i in range(self.N): for j in range(i + 1,self.N): ret += self.score[int(lis[i])][int(lis[j])] return ret if s in self.dp[n]: return self.dp[n][s] ret = 0 for i in range(1,self.N + 1): if self.used[i]: continue self.used[i] = True ret = max(ret,self.dfs(n + 1,s * 10 + i)) self.used[i] = False self.dp[n][s] = ret return self.dp[n][s] def run(self): self.N,self.M = map(int,input().split()) self.dp = [{}] * (self.N + 1) self.used = [False for i in range(self.N + 1)] self.score = [[0 for j in range(self.N + 1)]for i in range(self.N + 1)] for i in range(self.M): f,s,t = map(int,input().split()) self.score[f + 1][s + 1] = t print(self.dfs(0,0)) if __name__ == '__main__': Main().run()