結果

問題 No.90 品物の並び替え
ユーザー spaciaspacia
提出日時 2016-01-17 22:40:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 191 ms / 5,000 ms
コード長 1,283 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 78,204 KB
実行使用メモリ 55,832 KB
最終ジャッジ日時 2023-10-20 00:31:38
合計ジャッジ時間 3,649 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,532 KB
testcase_01 AC 96 ms
55,048 KB
testcase_02 AC 55 ms
53,540 KB
testcase_03 AC 65 ms
53,544 KB
testcase_04 AC 66 ms
53,544 KB
testcase_05 AC 95 ms
54,580 KB
testcase_06 AC 94 ms
55,032 KB
testcase_07 AC 57 ms
53,544 KB
testcase_08 AC 56 ms
53,540 KB
testcase_09 AC 191 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.math.*;

class Main {
	
	static int max = 10 , n , ans = 0;
	static int[][] scoreBoard = new int[max][max];
	static int[] prod;
	static boolean[] check;
	
	public static void out (Object o) {
		System.out.println(o);
	}
	
	public static int calc () {
		int ret = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				ret += scoreBoard[prod[i]][prod[j]];
			}
		}
		return ret;
	}
	
	public static void solve (int cnt) {
		if (cnt == n) ans = Math.max(ans , calc());
		for (int i = 0; i < n; i++) {
			if (check[i]) continue;
			check[i] = true;
			prod[cnt] = i;
			solve(cnt + 1);
			check[i] = false;
			prod[cnt] = -1;
		}
	}
	
	public static void main (String[] args) throws IOException {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		String[] line = br.readLine().split(" ");
		n = Integer.parseInt(line[0]);
		int m = Integer.parseInt(line[1]);
		check = new boolean[n];
		prod = new int[n];
		Arrays.fill(prod , -1);
		
		for (int i = 0; i < m; i++) {
			line = br.readLine().split(" ");
			int a = Integer.parseInt(line[0]);
			int b = Integer.parseInt(line[1]);
			int c = Integer.parseInt(line[2]);
			scoreBoard[a][b] = c;
		}
		
		solve(0);
		
		out(ans);
	}
}
0