結果

問題 No.519 アイドルユニット
ユーザー pekempeypekempey
提出日時 2017-05-28 21:58:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 904 ms / 1,000 ms
コード長 870 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 78,456 KB
実行使用メモリ 70,992 KB
最終ジャッジ日時 2024-04-14 06:30:44
合計ジャッジ時間 8,954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 904 ms
70,932 KB
testcase_01 AC 900 ms
70,852 KB
testcase_02 AC 217 ms
20,304 KB
testcase_03 AC 14 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 14 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 14 ms
6,940 KB
testcase_15 AC 14 ms
6,940 KB
testcase_16 AC 15 ms
6,944 KB
testcase_17 AC 14 ms
6,940 KB
testcase_18 AC 15 ms
6,940 KB
testcase_19 AC 14 ms
6,940 KB
testcase_20 AC 14 ms
6,940 KB
testcase_21 AC 14 ms
6,944 KB
testcase_22 AC 15 ms
6,940 KB
testcase_23 AC 14 ms
6,944 KB
testcase_24 AC 53 ms
7,424 KB
testcase_25 AC 53 ms
7,560 KB
testcase_26 AC 54 ms
7,512 KB
testcase_27 AC 53 ms
7,636 KB
testcase_28 AC 54 ms
7,436 KB
testcase_29 AC 897 ms
70,856 KB
testcase_30 AC 900 ms
70,916 KB
testcase_31 AC 901 ms
70,992 KB
testcase_32 AC 900 ms
70,768 KB
testcase_33 AC 1 ms
6,944 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