結果
| 問題 | No.357 品物の並び替え (Middle) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-22 20:18:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,058 bytes |
| 記録 | |
| コンパイル時間 | 4,252 ms |
| コンパイル使用メモリ | 75,760 KB |
| 実行使用メモリ | 38,248 KB |
| 最終ジャッジ日時 | 2024-07-21 09:30:54 |
| 合計ジャッジ時間 | 5,283 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 17 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str[] = br.readLine().split(" ");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
int score[][] = new int[n][n];
for (int i = 0; i < m; i++) {
str = br.readLine().split(" ");
int a = Integer.parseInt(str[0]);
int b = Integer.parseInt(str[1]);
int s = Integer.parseInt(str[2]);
score[a][b] = s;
}
int dp[] = new int[(1 << n)];
for (int bit = 0; bit < (1 << n); bit++) {
for (int i = 0; i < n; i++) {
if ((bit & (1 << i)) == 0)
continue;
int cost = 0;
for (int j = i + 1; j < n; j++) {
if ((bit & (1 << j)) == 0)
continue;
cost = Math.max(cost, score[j][i]);
}
int now = ((bit | (1 << i)));
dp[now] = Math.max(dp[now], dp[bit] + cost);
}
}
System.out.println(dp[(1 << n) - 1]);
}
}