結果

問題 No.90 品物の並び替え
ユーザー kano_townkano_town
提出日時 2014-12-08 21:18:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 751 ms / 5,000 ms
コード長 1,254 bytes
コンパイル時間 4,130 ms
コンパイル使用メモリ 74,788 KB
実行使用メモリ 56,740 KB
最終ジャッジ日時 2023-09-02 11:46:56
合計ジャッジ時間 6,999 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
55,816 KB
testcase_01 AC 214 ms
56,416 KB
testcase_02 AC 133 ms
56,096 KB
testcase_03 AC 166 ms
54,864 KB
testcase_04 AC 170 ms
56,604 KB
testcase_05 AC 226 ms
56,740 KB
testcase_06 AC 204 ms
56,524 KB
testcase_07 AC 170 ms
56,612 KB
testcase_08 AC 131 ms
55,684 KB
testcase_09 AC 751 ms
56,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Yukicoder90 {

	static int n, m, buf, max = -1;
	static int[] item;
	static int[][] score;
	static boolean cover = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		item = new int[n];
		score = new int[m][3];

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < 3; j++) {
				score[i][j] = sc.nextInt();
			}
		}

		// 全探索
		uwaaaaa(0);

		System.out.println(max);
	}

	static void uwaaaaa(int now) {
		if (now == n) {
			buf = 0;
			for (int i = 0; i < m; i++) {
				
				if (compereIndex(score[i][0], score[i][1])) {
					buf += score[i][2];
				}
			}
			max = Math.max(max, buf);
			return;
		}
		for (int i = 0; i < n; i++) {
			cover = true;
			for (int j = 0; j < now; j++) {
				if (now != 0 && i == item[j]) {
					cover = false;
					break;
				}
			}
			if (cover) {
				item[now] = i;
				uwaaaaa(now + 1);
			}
		}
	}

	static boolean compereIndex(int a, int b) {
		int aPos = 0, bPos = 0;
		for (int i = 0; i < n; i++) {
			if (a == item[i]) aPos = i;
			if (b == item[i]) bPos = i;
		}
		if (aPos < bPos) return true;
		else return false;
	}
}
0