cf 1316E(贪心优化的状态压缩dp) 好题

题意:
给你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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值