結果

問題 No.357 品物の並び替え (Middle)
ユーザー buno15buno15
提出日時 2020-10-22 20:18:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,058 bytes
コンパイル時間 3,128 ms
コンパイル使用メモリ 73,420 KB
実行使用メモリ 52,600 KB
最終ジャッジ日時 2023-09-28 14:49:14
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int m = Integer.parseInt(str[1]);

		int score[][] = new int[n][n];

		for (int i = 0; i < m; i++) {
			str = br.readLine().split(" ");

			int a = Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			int s = Integer.parseInt(str[2]);

			score[a][b] = s;
		}

		int dp[] = new int[(1 << n)];

		for (int bit = 0; bit < (1 << n); bit++) {
			for (int i = 0; i < n; i++) {
				if ((bit & (1 << i)) == 0)
					continue;

				int cost = 0;
				for (int j = i + 1; j < n; j++) {
					if ((bit & (1 << j)) == 0)
						continue;

					cost = Math.max(cost, score[j][i]);
				}

				int now = ((bit | (1 << i)));
				dp[now] = Math.max(dp[now], dp[bit] + cost);
			}
		}

		System.out.println(dp[(1 << n) - 1]);
	}
}
0