結果

問題 No.90 品物の並び替え
ユーザー kuramukuramu
提出日時 2016-01-23 21:36:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,469 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 77,532 KB
実行使用メモリ 56,016 KB
最終ジャッジ日時 2023-10-21 13:52:26
合計ジャッジ時間 3,698 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int[][] score;
	static int N;
	static int[] num;
	static boolean[] check;
	static int max;
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	String[] temps = stdReader.readLine().split(" ");
	    	N = Integer.parseInt(temps[0]);
	    	int m = Integer.parseInt(temps[1]);
	    	score = new int[N][N];
	    	for(int i=0;i<N;i++){
		    	Arrays.fill(score[i], 0);
	    	}
	    	num = new int[N];
	    	Arrays.fill(num, -1);
	    	check = new boolean[N];
	    	for(int i=0;i<m;i++){
	    		String[] temps2 = stdReader.readLine().split(" ");
	    		int item1 = Integer.parseInt(temps2[0]);
	    		int item2 = Integer.parseInt(temps2[1]);
	    		score[item1][item2] = Math.max(score[item1][item2], Integer.parseInt(temps2[2]));	
	    	}
	    	solve(0);
	    	System.out.println(max);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
		
	public static void getAns(){
		int ans = 0;
		for(int i=0;i<N-1;i++){
			ans += score[num[i]][num[i+1]];
		}
		max = Math.max(max, ans);
	}
	
	public static void solve(int n){
		if(n == N) {
			getAns();
		}else{
			for(int i=0;i<N;i++){
				if(!check[i]){
					check[i] = true;
					num[n] = i;
					solve(n+1);
					num[n] = -1;
					check[i] = false;
				}
			}
		}
	}
}
0