結果

問題 No.90 品物の並び替え
ユーザー tenten
提出日時 2020-12-18 16:56:07
言語 Java
(openjdk 23)
結果
AC  
実行時間 470 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 78,592 KB
実行使用メモリ 61,268 KB
最終ジャッジ日時 2024-09-21 09:12:15
合計ジャッジ時間 5,412 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[][] scores;
    static int max = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
        scores = new int[n][n];
        for (int i = 0; i < m; i++) {
            scores[sc.nextInt()][sc.nextInt()] = sc.nextInt();
        }
        check(0, 0, new HashSet<>());
        System.out.println(max);
    }
    
    static void check(int idx, int total, HashSet<Integer> used) {
        if (idx == n) {
            max = Math.max(max, total);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used.contains(i)) {
                continue;
            }
            int tmp = 0;
            for (int x : used) {
                tmp += scores[x][i];
            }
            used.add(i);
            check(idx + 1, total + tmp, used);
            used.remove(i);
        }
    }
}
0