結果

問題 No.90 品物の並び替え
コンテスト
ユーザー kroton
提出日時 2014-12-09 15:41:26
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 514 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 552 ms
コンパイル使用メモリ 72,408 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-05 00:49:23
合計ジャッジ時間 1,054 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
using namespace std;

int N, M;
int score[11][11];

int dfs(int mask){
	int res = 0;
	for(int i=0;i<N;i++){
		if((mask >> i) & 1)continue;

		int tmp = 0;
		for(int j=0;j<N;j++){
			if((mask >> j) & 1){
				tmp += score[j][i];
			}
		}

		tmp += dfs(mask | (1 << i));
		res = max(res, tmp);
	}
	return res;
}

int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a, b, c;
		cin >> a >> b >> c;

		score[a][b] = c;
	}

	cout << dfs(0) << endl;
	return 0;
}
0