結果

問題 No.90 品物の並び替え
ユーザー krotonkroton
提出日時 2014-12-07 20:47:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 475 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 6,676 KB
実行使用メモリ 5,984 KB
最終ジャッジ日時 2023-09-02 10:23:41
合計ジャッジ時間 1,255 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,956 KB
testcase_01 AC 13 ms
5,984 KB
testcase_02 AC 11 ms
5,984 KB
testcase_03 AC 11 ms
5,852 KB
testcase_04 AC 12 ms
5,892 KB
testcase_05 AC 13 ms
5,896 KB
testcase_06 AC 13 ms
5,852 KB
testcase_07 AC 11 ms
5,980 KB
testcase_08 AC 11 ms
5,964 KB
testcase_09 AC 15 ms
5,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

dp = [-1] * (1 << 10)
score = [0] * 1000

N, M = map(int, raw_input().split())
for t in xrange(M):
	a, b, c = map(int, raw_input().split())
	score[a * N + b] = c
	
def solve(m):
	if dp[m] != -1:
		return dp[m]
	
	res = 0
	for i in xrange(0, N):
		if (m >> i) & 1 == 0:
			tmp = 0
			for j in xrange(0, N):
				if (m >> j) & 1 == 1:
					tmp += score[i * N + j]
			res = max(res, tmp + solve(m | (1 << i)))
			
	dp[m] = res
	return res
	
print solve(0)
0