結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-19 00:33:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 1,000 ms |
| コード長 | 724 bytes |
| コンパイル時間 | 1,546 ms |
| コンパイル使用メモリ | 167,680 KB |
| 実行使用メモリ | 68,992 KB |
| 最終ジャッジ日時 | 2024-10-02 13:39:19 |
| 合計ジャッジ時間 | 4,167 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#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;
}