結果
問題 |
No.519 アイドルユニット
|
ユーザー |
|
提出日時 | 2024-08-13 23:20:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 244 ms / 1,000 ms |
コード長 | 1,429 bytes |
コンパイル時間 | 1,664 ms |
コンパイル使用メモリ | 125,092 KB |
最終ジャッジ日時 | 2025-02-23 22:44:00 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,ll> P; typedef pair<int,P> PP; const ll MOD=998244353; int main(){ int N; cin>>N; vector<vector<int>> F(N,vector<int>(N)); for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cin>>F[i][j]; } } //unordered_map<int,int> ump; vector<int> ump(1<<N); for(int S=0;S<(1<<N);S++){ ump[S]=-1; for(int i=0;i<N;i++){ if((S>>i)&1) continue; ump[S]=i; break; } } /* vector<int> dp(1<<N,-inf); dp[0]=0; for(int S=0;S<(1<<N);S++){ int idx=ump[S]; if(idx==-1) continue; for(int j=idx+1;j<N;j++){ if(S>>j&1) continue; dp[S|(1<<idx)|(1<<j)]=max(dp[S|(1<<idx)|(1<<j)],dp[S]+F[idx][j]); } } */ map<int,int> dp; dp[0]=0; for(auto [S,v]:dp){ int idx=ump[S]; if(idx==-1) continue; for(int j=idx+1;j<N;j++){ if((S>>j)&1) continue; dp[S|(1<<idx)|(1<<j)]=max(dp[S|(1<<idx)|(1<<j)],dp[S]+F[idx][j]); } } int all=(1<<N)-1; cout<<dp[all]<<endl; }