結果
| 問題 |
No.357 品物の並び替え (Middle)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-04-01 22:39:01 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 943 bytes |
| コンパイル時間 | 1,889 ms |
| コンパイル使用メモリ | 141,440 KB |
| 実行使用メモリ | 21,888 KB |
| 最終ジャッジ日時 | 2024-06-12 03:19:10 |
| 合計ジャッジ時間 | 3,084 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 WA * 1 |
ソースコード
import std.stdio;
import std.array;
import std.conv;
import std.algorithm;
uint[string] dp;
void main() {
uint n, m; readf("%s %s\n", &n, &m);
uint[][] score = loadScoreTable(n, m);
uint[] a; foreach (i; 0..n) a ~= i;
writeln(dfs([], a, score));
}
uint[][] loadScoreTable(uint n, uint m) {
uint[][] table = new uint[][](n, n);
foreach (_; 0..m) {
uint i, j, s;
readf("%s %s %s\n", &i, &j, &s);
table[i][j] = s;
}
return table;
}
uint dfs(uint[] done, const uint[] left, const uint[][] score) {
sort(done);
string key = done.map!(to!string).join;
if (key in dp) return dp[key];
if (0 == left.length) return 0;
uint maxScore = 0;
foreach (i; left) {
uint s = 0;
foreach (j; done) s += score[i][j];
s += dfs(done ~ i, left.dup.remove!(a => i == a), score);
maxScore = max(maxScore, s);
}
return dp[key] = maxScore;
}