結果

問題 No.519 アイドルユニット
ユーザー gigimegigime
提出日時 2017-05-28 23:24:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,241 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 170,896 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:45:23
合計ジャッジ時間 3,101 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 28 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 9 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 9 ms
4,348 KB
testcase_18 AC 9 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 10 ms
4,348 KB
testcase_21 AC 9 ms
4,348 KB
testcase_22 AC 10 ms
4,348 KB
testcase_23 AC 10 ms
4,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 13 ms
4,348 KB
testcase_28 WA -
testcase_29 AC 44 ms
4,348 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
const int MAX_N = 24;
int edge [MAX_N] [MAX_N];
const int INF = 1e9;
const int MAGIC = 1000;

int bit_count(int x)
{
	int res = 0;
	for(;x;x -= x & -x) res++;
	return res;
}

int solve(vector<int>& v)
{
	int n = v.size();
	vector<int> dp(1 << n,-INF);
	dp [0] = 0;
	FOR(mask,0,1 << n) if(dp [mask] >= 0){
		FOR(i,0,n) if((mask >> i & 1) == 0){
			FOR(j,i + 1,n) if((mask >> j & 1) == 0){
				int nmask = mask | (1 << i) | (1 << j);
				chmax(dp [nmask],dp [mask] + edge [v [i]] [v [j]]);
			}
			break;
		}
	}
	return dp [(1 << n) - 1];
}

int main()
{
	scanf("%d",&N);
	FOR(i,0,N) FOR(j,0,N){
		scanf("%d",&edge [i] [j]);
	}

	int ans = 0,cnt = 0;
	FOR(mask,0,1 << N) if(bit_count(mask) == N / 2 / 2 * 2){
		vector<int> v,w;
		FOR(i,0,N){
			if(mask >> i & 1){
				v.push_back(i);
			}
			else{
				w.push_back(i);
			}
		}
		chmax(ans,solve(v) + solve(w));
		if(++cnt == MAGIC) break;
	}

	printf("%d\n",ans);

	return 0;
}
0