結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-30 14:52:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 898 ms / 1,000 ms |
| コード長 | 1,266 bytes |
| コンパイル時間 | 2,095 ms |
| コンパイル使用メモリ | 199,196 KB |
| 実行使用メモリ | 71,388 KB |
| 最終ジャッジ日時 | 2025-03-30 14:52:46 |
| 合計ジャッジ時間 | 10,236 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=(x<<1)+(x<<3)+(ch&15);
ch=getchar();
}
return x*f;
}
inline void write(int x)
{
if(x<0)x=-x,putchar('-');
if(x>9)write(x/10);
putchar(x%10+48);
return;
}
const int M=30,N=2e7+7,INF=0x3f3f3f3f;
struct node{int v,w;};
vector<node>mp[M];
int n,ans,kk[M][M],st[N],f[N];
inline void dfs(int u,int res)
{
if(u>n)
{
ans=max(res,ans);
return;
}
for(auto t:mp[u])
{
int v=t.v,w=t.w;
if(st[v])continue;
st[u]=v;
st[v]=u;
int k=u;
while(st[k])++k;
dfs(k,res+w);
st[u]=0;
st[v]=0;
}
}
mt19937 dg(time(0));
int main()
{
n=read();
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
{
kk[i][j]=read();
if(~kk[i][j])mp[i].emplace_back((node){j,kk[i][j]});
}
if(n<=16)dfs(1,0);
else
{
for(int S=3;S<(1<<n);++S)
{
if(__builtin_popcount(S)&1)continue;
int cnt=0;
for(int j=0;j<n;++j)if((1<<j)&S)st[++cnt]=j;
for(int j=2;j<=cnt;++j)
f[S]=max(f[S],f[S-(1<<st[1])-(1<<st[j])]+kk[st[1]+1][st[j]+1]);
}
ans=f[(1<<n)-1];
}
write(ans);
return 0;
}