結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
hiyokko2
|
| 提出日時 | 2017-05-28 23:20:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,067 bytes |
| コンパイル時間 | 677 ms |
| コンパイル使用メモリ | 79,664 KB |
| 実行使用メモリ | 148,080 KB |
| 最終ジャッジ日時 | 2024-09-21 15:59:45 |
| 合計ジャッジ時間 | 5,007 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 << 24];
int rec(int S)
{
if (dp[S] != -1) return dp[S];
if (S == 0) return dp[S] = 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 dp[S] = 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;
}
*/
memset(dp, -1, sizeof(dp));
cout << rec((1 << n) - 1) << endl;
}
hiyokko2