結果

問題 No.90 品物の並び替え
ユーザー olpheolphe
提出日時 2017-06-11 00:42:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 1,464 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 118,704 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:37:03
合計ジャッジ時間 1,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, K, Q, M;
long long int ans;

int box[9][9];

void Search(int depth, vector<int>num, vector<bool>flag) {
	if (depth == N) {
		long long int bag = 0;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				bag += box[num[i]][num[j]];
			}
		}
		ans = max(bag, ans);
		return;
	}
	for (int i = 0; i < N; i++) {
		if (!flag[i]) {
			num.push_back(i);
			flag[i] = true;
			Search(depth + 1, num, flag);
			num.pop_back();
			flag[i] = false;
		}
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		box[a][b] = c;
	}
	Search(0, vector<int>(0), vector<bool>(N, false));
	cout << ans << endl;
	return 0;
}
0