結果

問題 No.90 品物の並び替え
ユーザー tookunn_1213tookunn_1213
提出日時 2016-06-28 23:01:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 913 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 65,880 KB
最終ジャッジ日時 2024-04-20 03:11:07
合計ジャッジ時間 9,451 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 765 ms
16,832 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 102 ms
11,520 KB
testcase_04 AC 100 ms
11,648 KB
testcase_05 AC 751 ms
16,836 KB
testcase_06 AC 763 ms
16,964 KB
testcase_07 AC 36 ms
11,008 KB
testcase_08 AC 27 ms
10,880 KB
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0