結果

問題 No.519 アイドルユニット
ユーザー vjudge1
提出日時 2025-03-15 13:17:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 51 ms / 1,000 ms
コード長 940 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 160,760 KB
実行使用メモリ 69,184 KB
最終ジャッジ日時 2025-03-15 13:17:49
合計ジャッジ時間 3,486 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 24;
int n;
int a[N][N];
int f[1 << N];
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    memset(f, -1, sizeof(f));
    f[0] = 0;
    for (int S = 0; S < (1 << n); S++)
    {
        if (f[S] == -1)
            continue;
        for (int i = 0; i < n; i++)
            if (((S >> i) & 1) == 0)
            {
                for (int j = i + 1; j < n; j++)
                    if (((S >> j) & 1) == 0)
                    {
                        int nxt = S ^ (1 << i) ^ (1 << j);
                        f[nxt] = max(f[nxt], f[S] + a[i][j]);
                    }
                break;
            }
    }
    cout << f[(1 << n) - 1] << endl;
    return 0;
}
0