結果

問題 No.519 アイドルユニット
ユーザー myantamyanta
提出日時 2017-05-28 22:44:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 772 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 41,032 KB
実行使用メモリ 11,652 KB
最終ジャッジ日時 2023-10-21 14:26:55
合計ジャッジ時間 4,777 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:51: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |                         for(int j=0;j<n;j++) scanf("%d", &f[i][j]);
      |                                              ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<vector>


using namespace std;

using vi=vector<int>;
using vvi=vector<vi>;


void solve_i(vvi& f, long used, int score, int& ans)
{
	int n=f.size();
	int i, j;

	if(used==((1<<n)-1))
	{
		if(ans<score) ans=score;
		return;
	}

	for(i=0;i<n;i++)
	{
		if((used>>i)&1) continue;
		used|=(1<<i);
		for(j=i+1;j<n;j++)
		{
			if((used>>j)&1) continue;
			used|=(1<<j);
			solve_i(f, used, score+f[i][j], ans);
			used&=~(1<<j);
		}
		used&=~(1<<i);
	}
}


int solve(vvi& f)
{
	int ans=0;

	solve_i(f, 0, 0, ans);
	return ans;
}


int main(void)
{
	vvi f;
	int n;

	while(scanf("%d", &n)==1)
	{
		f.resize(n);
		for(int i=0;i<n;i++)
		{
			f[i].resize(n);
			for(int j=0;j<n;j++) scanf("%d", &f[i][j]);
		}
		printf("%d\n", solve(f));
	}

	return 0;
}
0