結果
問題 |
No.519 アイドルユニット
|
ユーザー |
![]() |
提出日時 | 2017-05-28 23:11:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,006 bytes |
コンパイル時間 | 624 ms |
コンパイル使用メモリ | 80,732 KB |
実行使用メモリ | 279,144 KB |
最終ジャッジ日時 | 2024-09-21 15:50:42 |
合計ジャッジ時間 | 4,970 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 33 |
ソースコード
//#define LOCAL #include <fstream> #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <queue> #include <cstring> #define int long long //typedef long long ll; #define rep(i, n) for(int i=0; i<(n); i++) using namespace std; int n; int F[30][30]; int dp[1 << 25]; int rec(int S) { if (dp[S] != -1) return dp[S]; if (S == 0) return 0; int mx = -1; for (int i=0; i<(n-1); i++) { for (int j=i+1; j<n; j++) { if ((S >> i & 1) && (S >> j & 1)) { int tempS = S; tempS = tempS & ~(1 << i); tempS = tempS & ~(1 << j); mx = max(mx, rec(tempS) + F[i][j]); } } } return mx; } signed main() { #ifdef LOCAL ifstream in("input.txt"); cin.rdbuf(in.rdbuf()); #endif cin >> n; rep(i, n) rep(j, n) { cin >> F[i][j]; } rep(i,(1<<(n+1))) { dp[i] = -1; } cout << rec((1 << n) - 1) << endl; }