結果

問題 No.519 アイドルユニット
ユーザー myanta
提出日時 2017-05-28 22:44:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 772 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 40,832 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-09-21 15:42:01
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 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