結果
問題 | No.519 アイドルユニット |
ユーザー |
|
提出日時 | 2017-05-28 23:28:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 694 bytes |
コンパイル時間 | 1,630 ms |
コンパイル使用メモリ | 166,732 KB |
実行使用メモリ | 29,184 KB |
最終ジャッジ日時 | 2024-10-02 07:32:49 |
合計ジャッジ時間 | 6,049 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 33 |
ソースコード
#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] != 0) 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;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {cin >> f[i][j];}}cout << solve(0) << endl;return 0;}