1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int n, k, ans; int Max[33];
void dfs(int d, int s, int sum) { if (d == k) { ans = max(ans, sum); return; } for (int i = s; i; i = (i - 1) & s) { dfs(d + 1, s ^ i, sum + Max[i]); } }
int main() { int t; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &k); memset(Max, 0, sizeof Max); for (int i = 0; i < n; ++i) { int a[5]; for (int j = 0; j < 5; ++j) { scanf("%d", &a[j]); } for (int j = 31; j > 0; --j) { int sum = 0; for (int l = 0; l < 5; ++l) { if (j & (1 << l)) { sum += a[l]; } } Max[j] = max(Max[j], sum); } } k = min(k, 5), ans = 0; dfs(0, 31, 0); printf("%d\n", ans); } return 0; }
|