結果

問題 No.519 アイドルユニット
ユーザー finefine
提出日時 2017-06-19 00:33:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 724 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 163,492 KB
実行使用メモリ 69,184 KB
最終ジャッジ日時 2024-04-10 11:40:11
合計ジャッジ時間 3,575 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
69,108 KB
testcase_01 AC 35 ms
69,124 KB
testcase_02 AC 25 ms
69,040 KB
testcase_03 AC 20 ms
69,084 KB
testcase_04 AC 20 ms
69,032 KB
testcase_05 AC 20 ms
68,996 KB
testcase_06 AC 19 ms
69,048 KB
testcase_07 AC 20 ms
69,152 KB
testcase_08 AC 19 ms
68,932 KB
testcase_09 AC 19 ms
68,840 KB
testcase_10 AC 20 ms
69,048 KB
testcase_11 AC 20 ms
69,112 KB
testcase_12 AC 19 ms
69,044 KB
testcase_13 AC 21 ms
69,056 KB
testcase_14 AC 20 ms
69,028 KB
testcase_15 AC 20 ms
69,064 KB
testcase_16 AC 19 ms
69,184 KB
testcase_17 AC 20 ms
68,964 KB
testcase_18 AC 20 ms
68,976 KB
testcase_19 AC 20 ms
69,124 KB
testcase_20 AC 20 ms
69,004 KB
testcase_21 AC 20 ms
69,060 KB
testcase_22 AC 19 ms
69,156 KB
testcase_23 AC 21 ms
68,872 KB
testcase_24 AC 21 ms
69,160 KB
testcase_25 AC 21 ms
68,980 KB
testcase_26 AC 20 ms
69,016 KB
testcase_27 AC 21 ms
69,164 KB
testcase_28 AC 22 ms
69,080 KB
testcase_29 AC 35 ms
69,132 KB
testcase_30 AC 40 ms
69,004 KB
testcase_31 AC 35 ms
69,072 KB
testcase_32 AC 36 ms
68,992 KB
testcase_33 AC 19 ms
69,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int n;
int f[24][24];
int dp[1 << 24];

int solve(int used) {
	if (used == (1 << n) - 1) return 0;
	if (dp[used] != -1) return dp[used];
	int res = 0;
	int cur = 0;
	for (int i = 0; i < n; i++) {
		if (used & (1 << i)) continue;
		cur = i;
		break;
	}
	for (int i = cur + 1; i < n; i++) {
		if (used & (1 << i)) continue;
		int nex = used;
		nex |= (1 << cur);
		nex |= (1 << i);
		res = max(res, solve(nex) + f[cur][i]);
	}
	return dp[used] = res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> f[i][j];
		}
	}
	cout << solve(0) << endl;
	return 0;
}
0