結果

問題 No.90 品物の並び替え
ユーザー packet0packet0
提出日時 2014-12-07 20:20:52
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 798 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 133,580 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 19:20:10
合計ジャッジ時間 2,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 16 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 3 ms
4,372 KB
testcase_04 AC 3 ms
4,368 KB
testcase_05 AC 17 ms
4,372 KB
testcase_06 AC 17 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 135 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

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));
}

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

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

0