結果

問題 No.90 品物の並び替え
ユーザー scachescache
提出日時 2014-12-07 19:25:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 208 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 3,327 ms
コンパイル使用メモリ 74,440 KB
実行使用メモリ 56,508 KB
最終ジャッジ日時 2023-09-02 09:20:42
合計ジャッジ時間 5,639 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,260 KB
testcase_01 AC 162 ms
56,508 KB
testcase_02 AC 125 ms
55,920 KB
testcase_03 AC 160 ms
56,384 KB
testcase_04 AC 156 ms
56,408 KB
testcase_05 AC 166 ms
54,452 KB
testcase_06 AC 161 ms
56,172 KB
testcase_07 AC 134 ms
55,908 KB
testcase_08 AC 126 ms
55,944 KB
testcase_09 AC 208 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main2 {
	public static void main(String[] args) {
		Main2 p = new Main2();
	}

	public Main2() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		score = new int[n][n];
		for(int i=0;i<m;i++)
			score[sc.nextInt()][sc.nextInt()] =sc.nextInt();
		solve(score);
	}

	private int[][] score;
	private int isUsed;
	private int[] a;
	public void solve(int[][] score) {
		isUsed = 0;
		a = new int[score.length];
		int res = rec(0);
		System.out.println(res);
	}

	private int rec(int cur) {
		if(cur==score.length)
			return calc();
		
		int res=0;
		for(int i=0;i<score.length;i++){
			if((isUsed & (1<<i))!=0)
				continue;
			
			isUsed += (1<<i);
			a[cur] = i;
			res = Math.max(res, rec(cur+1));
			isUsed -= (1<<i);
		}
			
		return res;
	}
	
	private int calc(){
		int res = 0;
		for(int i=0;i<score.length;i++){
			for(int j=i+1;j<score[i].length;j++){
				res += score[a[i]][a[j]];
			}
		}
		return res;
	}

}
0