結果

問題 No.90 品物の並び替え
ユーザー kano_townkano_town
提出日時 2014-12-08 21:13:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,249 bytes
コンパイル時間 7,636 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 56,676 KB
最終ジャッジ日時 2023-09-02 11:46:48
合計ジャッジ時間 7,793 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,536 KB
testcase_01 WA -
testcase_02 AC 123 ms
55,788 KB
testcase_03 AC 157 ms
56,200 KB
testcase_04 WA -
testcase_05 AC 211 ms
56,444 KB
testcase_06 AC 198 ms
56,568 KB
testcase_07 WA -
testcase_08 AC 124 ms
55,984 KB
testcase_09 AC 732 ms
56,508 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