結果

問題 No.90 品物の並び替え
ユーザー uafr_csuafr_cs
提出日時 2015-05-15 18:25:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 74,156 KB
実行使用メモリ 58,432 KB
最終ジャッジ日時 2023-09-20 08:11:11
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,696 KB
testcase_01 WA -
testcase_02 AC 130 ms
55,480 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = Integer.MIN_VALUE;
			for(int i = 0; i < N; i++){
				if(!selected[i]){
					selected[i] = true;
					items[deep] = i;
					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));
	}
}
0