题意:
给你n个人,从中选出p个球员和k个观众,第i个人作为观众产生价值ai,第i个人作为j号球员产生价值Ci,j ,求最大价值
(2≤n≤105,1≤p≤7,1≤k,p+k≤n,ai<109,ci,j<109)
输入
第1行输入n p k
第2行分别输入ai
第3行到第3+n行,每行p个数字表示Ci,j
输出
一个整数,表示最大价值
样例输入:
6 2 3
78 93 9 17 13 78
80 97
30 52
26 17
56 68
60 36
84 55
样例输出:
377
代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define l(x) ((x)<<1)
#define r(x) ((x)<<1|1)
#define lowbit(x) ((x)&(-(x)))
#define ms(a,b) memset(a,b,sizeof(a))
#define NSYNC std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
using namespace std;
struct Player {
ll com[7], aud;
bool operator<(const Player &b) {
return aud > b.aud;
}
}a[111111];
ll n, p, k,dp[111111][128],len;
int main() {
scanf("%lld%lld%lld", &n, &p, &k);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i].aud);
for (int i = 1; i <= n; i++)
for (int j = 0; j < p; j++)
scanf("%lld", &a[i].com[j]);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (1 << p); j++) {
len = 0;
for (int c = 0; c < p; c++)
if ((j >> c) & 1)
len++;
dp[i][j] = dp[i - 1][j];
if (len + k >= i && len < i)
dp[i][j] += a[i].aud;
for (int c = 0; c < p; c++)
if ((j >> c) & 1) {
int now = j - (1 << c);
dp[i][j] = max(dp[i][j], dp[i - 1][now] + a[i].com[c]);
}
}
}
printf("%lld\n", dp[n][(1 << p) - 1]);
return 0;
}