結果

問題 No.90 品物の並び替え
ユーザー uafr_csuafr_cs
提出日時 2015-05-15 18:26:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 210 ms / 5,000 ms
コード長 1,225 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 76,140 KB
実行使用メモリ 57,576 KB
最終ジャッジ日時 2023-09-20 08:11:16
合計ジャッジ時間 4,581 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,932 KB
testcase_01 AC 169 ms
55,900 KB
testcase_02 AC 125 ms
57,576 KB
testcase_03 AC 156 ms
56,380 KB
testcase_04 AC 156 ms
56,144 KB
testcase_05 AC 170 ms
56,356 KB
testcase_06 AC 165 ms
56,072 KB
testcase_07 AC 156 ms
56,228 KB
testcase_08 AC 124 ms
55,692 KB
testcase_09 AC 210 ms
55,672 KB
権限があれば一括ダウンロードができます

ソースコード

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));
	}
}
0