結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-22 13:01:24 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 381 ms / 5,000 ms |
| コード長 | 999 bytes |
| コンパイル時間 | 2,267 ms |
| コンパイル使用メモリ | 77,600 KB |
| 実行使用メモリ | 49,696 KB |
| 最終ジャッジ日時 | 2024-07-07 23:04:34 |
| 合計ジャッジ時間 | 4,355 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
import java.util.*;
public class Main {
static int n;
static int[][] matrix;
static int max = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int m = sc.nextInt();
matrix = new int[n][n];
for (int i = 0; i < m; i++) {
matrix[sc.nextInt()][sc.nextInt()] = sc.nextInt();
}
search(0, 0, new HashSet<Integer>());
System.out.println(max);
}
static void search(int idx, int score, HashSet<Integer> used) {
if (idx >= n) {
max = Math.max(max, score);
return;
}
for (int i = 0; i < n; i++) {
if (used.contains(i)) {
continue;
}
int added = 0;
for (int x : used) {
added += matrix[x][i];
}
used.add(i);
search(idx + 1, score + added, used);
used.remove(i);
}
}
}
htensai