#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 505;
const int maxK = 7;
#define T tuple<int, vector<int>, vector<int>, array<int, 505>>
int n, k, c, arr[maxN][maxK];
T get(vector<int> v, array<int, 505> a) {
vector<int> ans = v;
for (int _ = (int)ans.size() + 1; _ <= k; _++) {
int mx = 0;
for (int i = 1; i <= n; i++) {
bool f = 1;
for (int j : ans) if (i == j) f = 0;
if (!f) continue;
if (arr[i][_] > arr[mx][_] && a[i] == 0) mx = i;
}
if (mx == 0) return {-1, ans, v, a};
ans.pb(mx);
}
int sum = 0;
for (int _ = 1; _ <= k; _++) {
int mx = 0;
for (int i : ans)
mx = max(mx, arr[i][_]);
sum += mx;
}
return {sum, ans, v, a};
}
void solve() {
cin >> n >> k >> c;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= k; j++) cin >> arr[i][j];
std::priority_queue<T> pq; pq.push(get({}, array<int, 505>{}));
while (!pq.empty()) {
T cur = pq.top(); pq.pop(); c--;
if (c == 0) { cout << get<0>(cur); return; }
vector<int> nv = get<2>(cur);
array<int, 505> na = get<3>(cur);
for (int i = nv.size(); i < k; i++) {
na[get<1>(cur)[i]] = 1;
T now = get(nv, na);
if (get<0>(now) != -1) pq.push(now);
nv.pb(get<1>(cur)[i]);
}
}
cout << -1;
}
int32_t main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |