結果

問題 No.3011 品物の並び替え (Extra)
ユーザー packet0packet0
提出日時 2014-12-07 20:55:27
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 963 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 133,600 KB
実行使用メモリ 12,616 KB
最終ジャッジ日時 2023-09-02 19:20:49
合計ジャッジ時間 13,871 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.90 品物の並び替え
//No.98 品物の並び替え (Extra)

import std.stdio;

int[50][50] mat;
int N, M;

void main() {
	readf("%d %d\n", &N, &M);
	for(int i=0; i<M; i++) {
		int item1, item2, score;
		readf("%d %d %d\n", &item1, &item2, &score);
		mat[item1][item2] = score;
	}

	bool[] items;
	items.length = N;
	writeln(getScore(items, N));
}

ulong getScore(const bool[] used, const int remain) {
	ulong max = 0;
	if(!remain) {
		return 0;
	}

	for(int i=0; i<N; i++) {
		if(!used[i]) {
			bool[] tmp = used.dup;
			tmp[i] = true;
			ulong localMax = getScore(tmp, remain-1) + addScore(used, i, remain);
			if(localMax > max)
				max = localMax;
		}
	}
	return max;
}

ulong addScore(const bool[] used, const int item, const int remain) {
	ulong total = 0;
	int count = 0;
	for(int i=0; i<N && count<=remain; i++) {
		if(used[i])
			total += mat[i][item];
		else
			count++;
	}
	return total;
}

0