結果
問題 |
No.90 品物の並び替え
|
ユーザー |
![]() |
提出日時 | 2016-01-17 22:40:50 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 181 ms / 5,000 ms |
コード長 | 1,283 bytes |
コンパイル時間 | 2,070 ms |
コンパイル使用メモリ | 77,944 KB |
実行使用メモリ | 52,556 KB |
最終ジャッジ日時 | 2024-09-19 20:21:22 |
合計ジャッジ時間 | 3,407 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 9 |
ソースコード
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); } }