Submission #196839

#TimeUsernameProblemLanguageResultExecution timeMemory
196839FischerOlympiads (BOI19_olympiads)C++14
0 / 100
111 ms21244 KiB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;
int n, k, c;
int p[510][6];

struct Partition {
	vector<int> choice;
	vector<int> best;
	int cost;
	Partition(vector<int> A): choice(A) {
		vector<int> temp(k, 0);
		int cnt = 0;
		for (int i = 0; i < n; ++i) {
			if (choice[i] == 1) {
				best.push_back(i);
				for (int j = 0; j < k; ++j) {
					temp[j] = max(temp[j], p[i][j]);
				}
				cnt += 1;
			}
		}
		for (int i = cnt; i < k; ++i) {
			int mx = -1, id;
			for (int j = 0; j < n; ++j) {
				if (choice[j] == 0 and mx < p[j][i]) {
					mx = p[j][i];
					id = j;
				}
			}
			choice[id] = 1;
			best.push_back(id);
			for (int j = 0; j < k; ++j) {
				temp[j] = max(temp[j], p[id][j]);
			}
		}
		for (int i = 0; i < k; ++i) choice[best[i]] = 0;
		cost = accumulate(all(temp), 0);
	}

	bool operator <(Partition r) const{ 
		return cost < r.cost;
	}
};

int main() {
	cin >> n >> k >> c;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < k; ++j) {
			cin >> p[i][j];
		}
	}
	priority_queue<Partition> Q;
	Q.push(Partition(vector<int>(n, 0)));
	while (c--) {
		auto q = Q.top(); Q.pop();
		if (c == 0) {
			cout << q.cost << endl;
			break;
		}
		if (count_if(all(q.choice), 
			[](int x) {return x >= 0;}) == k) {
				continue;
		}
		for (int i = 0; i < k; ++i) {
			vector<int> choice = q.choice;		
			vector<int> best = q.best;
			choice[best[i]] = -1;
			for (int j = 0; j < i; ++j) {
				choice[best[j]] = 1;
			}
			Q.push(Partition(choice));
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...