結果

問題 No.90 品物の並び替え
コンテスト
ユーザー scache
提出日時 2014-12-07 19:25:59
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 120 ms / 5,000 ms
+ 626µs
コード長 1,053 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,207 ms
コンパイル使用メモリ 84,620 KB
実行使用メモリ 45,632 KB
最終ジャッジ日時 2026-07-25 14:05:52
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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