結果

問題 No.519 アイドルユニット
ユーザー kwm_tkwm_t
提出日時 2020-12-13 20:49:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 1,000 ms
コード長 829 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 180,016 KB
実行使用メモリ 8,384 KB
最終ジャッジ日時 2023-10-20 04:10:19
合計ジャッジ時間 4,391 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
8,384 KB
testcase_01 AC 185 ms
8,384 KB
testcase_02 AC 56 ms
5,484 KB
testcase_03 AC 8 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 8 ms
4,348 KB
testcase_20 AC 7 ms
4,348 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 19 ms
4,380 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 19 ms
4,380 KB
testcase_27 AC 19 ms
4,380 KB
testcase_28 AC 19 ms
4,380 KB
testcase_29 AC 179 ms
8,384 KB
testcase_30 AC 180 ms
8,384 KB
testcase_31 AC 181 ms
8,384 KB
testcase_32 AC 182 ms
8,384 KB
testcase_33 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
#define endl "\n"
int N;
vector<vector<int>> A(28, vector<int>(28));
map<long long, long long>dp;

long long dfs(long long v) {
	if (dp.count(v)) {
		return dp[v];
	}
	long long ret = -1e18;
	for (long long i = 0; i < N; ++i) {
		if (1 & (v >> i)) {
			for (long long j = i + 1; j < N; ++j) {
				if (1 & (v >> j)) {
					long long next = v;
					next = next & ~(1 << i);
					next = next & ~(1 << j);
					ret = max(ret, dfs(next) + A[i][j]);
				}
			}
			break;
		}
	}
	dp[v] = ret;
	return dp[v];
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> A[i][j];
		}
	}
	dp[(long long)0] = (long long)0;
	cout << dfs((1 << N) - 1) << endl;
	return 0;
}
0