結果

問題 No.519 アイドルユニット
ユーザー femtofemto
提出日時 2017-05-29 12:17:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 1,000 ms
コード長 656 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 164,760 KB
実行使用メモリ 69,200 KB
最終ジャッジ日時 2024-04-14 06:38:18
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
69,056 KB
testcase_01 AC 32 ms
69,004 KB
testcase_02 AC 23 ms
68,892 KB
testcase_03 AC 20 ms
69,160 KB
testcase_04 AC 20 ms
68,960 KB
testcase_05 AC 19 ms
68,964 KB
testcase_06 AC 20 ms
68,972 KB
testcase_07 AC 19 ms
68,884 KB
testcase_08 AC 19 ms
68,960 KB
testcase_09 AC 20 ms
68,960 KB
testcase_10 AC 20 ms
69,108 KB
testcase_11 AC 20 ms
68,948 KB
testcase_12 AC 20 ms
69,064 KB
testcase_13 AC 20 ms
69,116 KB
testcase_14 AC 19 ms
68,984 KB
testcase_15 AC 20 ms
68,972 KB
testcase_16 AC 21 ms
69,200 KB
testcase_17 AC 20 ms
69,084 KB
testcase_18 AC 20 ms
68,868 KB
testcase_19 AC 20 ms
69,016 KB
testcase_20 AC 21 ms
69,096 KB
testcase_21 AC 20 ms
69,044 KB
testcase_22 AC 21 ms
69,056 KB
testcase_23 AC 20 ms
69,152 KB
testcase_24 AC 21 ms
69,060 KB
testcase_25 AC 21 ms
69,188 KB
testcase_26 AC 21 ms
69,080 KB
testcase_27 AC 22 ms
68,992 KB
testcase_28 AC 20 ms
69,176 KB
testcase_29 AC 33 ms
68,996 KB
testcase_30 AC 33 ms
69,024 KB
testcase_31 AC 34 ms
68,960 KB
testcase_32 AC 32 ms
69,012 KB
testcase_33 AC 20 ms
69,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

int rec(int bit) {
	int& d = dp[bit];
	if(d != -1) return d;
	if(bit == 0) return 0;
	d = 0;
	for(int i = 0; i < N; i++) {
		if(bit >> i & 1) {
			for(int j = i + 1; j < N; j++) {
				if(bit >> j & 1) {
					int nbit = bit ^ (1 << i) ^ (1 << j);
					d = max(d, rec(nbit) + f[i][j]);
				}
			}
			break;
		}
	}
	return d;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			cin >> f[i][j];
		}
	}
	memset(dp, -1, sizeof dp);
	cout << rec((1 << N) - 1) << endl;

}
0