結果

問題 No.90 品物の並び替え
ユーザー krotonkroton
提出日時 2014-12-09 15:41:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 51,172 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 12:10:28
合計ジャッジ時間 1,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 30 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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