結果

問題 No.90 品物の並び替え
ユーザー uafr_cs
提出日時 2015-05-15 18:26:31
言語 Java
(openjdk 23)
結果
AC  
実行時間 183 ms / 5,000 ms
コード長 1,225 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 77,364 KB
実行使用メモリ 41,588 KB
最終ジャッジ日時 2024-07-06 03:59:06
合計ジャッジ時間 3,766 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static int dfs(final int N, int deep, boolean[] selected, int[] items, int[][] scores){
if(deep < N){
int max = 0;
for(int i = 0; i < N; i++){
if(!selected[i]){
selected[i] = true;
items[deep] = i;
max = Math.max(max, dfs(N, deep + 1, selected, items, scores));
selected[i] = false;
}
}
return max;
}else{
int score = 0;
for(int fst = 0; fst < N; fst++){
for(int snd = fst + 1; snd < N; snd++){
score += scores[items[fst]][items[snd]];
}
}
return score;
}
}
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
final int N = sc.nextInt();
final int M = sc.nextInt();
int[][] scores = new int[N][N];
for(int i = 0; i < M; i++){
final int A = sc.nextInt();
final int B = sc.nextInt();
final int score = sc.nextInt();
scores[A][B] = Math.max(scores[A][B], score);
}
System.out.println(dfs(N, 0, new boolean[N], new int[N], scores));
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0