結果
問題 |
No.519 アイドルユニット
|
ユーザー |
![]() |
提出日時 | 2017-05-28 23:11:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,002 bytes |
コンパイル時間 | 903 ms |
コンパイル使用メモリ | 79,140 KB |
実行使用メモリ | 144,896 KB |
最終ジャッジ日時 | 2024-09-22 17:55:47 |
合計ジャッジ時間 | 5,257 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)) { dp[i] = -1; } cout << rec((1 << n) - 1) << endl; }