結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-15 08:01:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 143 ms / 1,000 ms |
| コード長 | 1,181 bytes |
| コンパイル時間 | 958 ms |
| コンパイル使用メモリ | 88,156 KB |
| 最終ジャッジ日時 | 2025-01-17 00:58:33 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a = (a<MOD)?a:(a-MOD);
b = (b<MOD)?b:(b-MOD);
a += b;
a = (a<MOD)?a:(a-MOD);
}
std::map<int, ll> dp[15];
std::map<int, ll>::iterator itr;
ll f[25][25];
int main(void){
int n,m,i,j,mask,l,r,t;
ll tmp;
std::cin >> n; m = n/2;
for(i=0; i<n; ++i){
for(j=0; j<n; ++j){
std::cin >> f[i][j];
}
}
dp[0][0] = 0ll;
for(i=0; i<m; ++i){
for(itr = dp[i].begin(); itr != dp[i].end(); ++itr){
mask = (*itr).first;
tmp = (*itr).second;
for(j=0; j<n; ++j){
if(!(mask&(1<<j))){
l = j;
for(r=j+1; r<n; ++r){
if(mask&(1<<r)){
continue;
}
t = mask+(1<<l)+(1<<r);
if(dp[i+1].find(t) == dp[i+1].end()){
dp[i+1][t] = tmp + f[l][r];
}else{
dp[i+1][t] = std::max(dp[i+1][t],tmp + f[l][r]);
}
}
break;
}
}
}
}
std::cout << dp[m][(1<<n)-1] << std::endl;
return 0;
}