結果

問題 No.519 アイドルユニット
ユーザー pekempeypekempey
提出日時 2017-05-28 21:58:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 762 ms / 1,000 ms
コード長 870 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 76,956 KB
実行使用メモリ 70,684 KB
最終ジャッジ日時 2023-07-26 16:54:22
合計ジャッジ時間 8,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 762 ms
70,604 KB
testcase_01 AC 760 ms
70,684 KB
testcase_02 AC 182 ms
20,080 KB
testcase_03 AC 13 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 13 ms
4,384 KB
testcase_14 AC 13 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 12 ms
4,384 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 13 ms
4,380 KB
testcase_23 AC 13 ms
4,384 KB
testcase_24 AC 46 ms
7,240 KB
testcase_25 AC 46 ms
7,304 KB
testcase_26 AC 46 ms
7,256 KB
testcase_27 AC 46 ms
7,356 KB
testcase_28 AC 46 ms
7,172 KB
testcase_29 AC 761 ms
70,620 KB
testcase_30 AC 757 ms
70,548 KB
testcase_31 AC 760 ms
70,604 KB
testcase_32 AC 758 ms
70,604 KB
testcase_33 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

void updmax(int &x, int y) {
	x = std::max(x, y);
}

int main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int>> cost(n, std::vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			std::cin >> cost[i][j];
		}
	}
	
	constexpr int INF = 1e9;
	std::vector<int> dp(1 << n, -INF);
	dp[0] = 0;

	std::vector<bool> ok(1 << n);
	ok[0] = true;
	for (int i = 1; i < 1 << n; i++) {
		ok[i] = !ok[i & i - 1];
	}

	for (int i = 0; i < 1 << n; i++) {
		if (!ok[i]) {
			continue;
		}
		int j;
		for (j = 0; j < n; j++) {
			if (~i >> j & 1) {
				break;
			}
		}
		for (int k = j + 1; k < n; k++) {
			if (i >> k & 1) {
				continue;
			}
			updmax(dp[i | 1 << j | 1 << k], dp[i] + cost[j][k]);
		}
	}
	std::cout << dp[(1 << n) - 1] << std::endl;
}
0