結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-12-07 20:20:52 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 134 ms / 5,000 ms |
| コード長 | 798 bytes |
| コンパイル時間 | 1,540 ms |
| コンパイル使用メモリ | 133,612 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-12 01:45:03 |
| 合計ジャッジ時間 | 2,433 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
//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;
}