結果

問題 No.519 アイドルユニット
ユーザー vjudge1
提出日時 2025-03-18 22:08:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 801 ms / 1,000 ms
コード長 1,136 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 192,428 KB
実行使用メモリ 101,840 KB
最終ジャッジ日時 2025-03-18 22:08:16
合計ジャッジ時間 9,552 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pb push_back
#define umap unordered_map
#define mset multiset
#define pq priority_queue
#define ull unsigned long long
#define i128 __int128
#define ld long double
#define fixs fixed<<setprecision
const int maxn=24+10,maxs=(1<<24)+10;
int n,a[maxn][maxn],f[maxs];
short p[maxs];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) cin>>a[i][j];
    }
    for(int i=1;i<(1<<n);i++){
        p[i]=p[i>>1]+(i&1);
        if(p[i]&1) continue;
        int id=__lg(i&(-i))+1;
        for(int j=1;j<=n;j++){
            if(!(i&(1<<(j-1)))||j==id) continue;
            f[i]=max(f[i],a[id][j]+f[i-(1<<(id-1))-(1<<(j-1))]);
        }
    }
    cout<<f[(1<<n)-1]<<endl;
}
int main(){
    // freopen("group.in","r",stdin);
    // freopen("group.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}
/*
Samples
input:

output:

THINGS TODO:
??freopen???????
????
????????????
*/
0