PACM Team (多种重量的01背包+记录路径) 牛客

题面:
Since then on, Eddy found that physics is actually the most important thing in the contest. Thus, he wants to form a team to guide the following contestants to conquer the PACM contests(PACM is short for Physics, Algorithm, Coding, Math).

There are N candidate groups each composed of pi physics experts, ai algorithm experts, ci coding experts, mi math experts. For each group, Eddy can either invite all of them or none of them. If i-th team is invited, they will bring gi knowledge points which is calculated by Eddy’s magic formula. Eddy believes that the higher the total knowledge points is, the better a team could place in a contest. But, Eddy doesn’t want too many experts in the same area in the invited groups. Thus, the number of invited physics experts should not exceed P, and A for algorithm experts, C for coding experts, M for math experts.

Eddy is still busy in studying Physics. You come to help him to figure out which groups should be invited such that they doesn’t exceed the constraint and will bring the most knowledge points in total.
1 ≤ N ≤ 36
0 ≤ pi,ai,ci,mi,gi ≤ 36
0 ≤ P, A, C, M ≤ 36
题意:
Eddy现在想招募多支队伍辅助他,每一个队伍有4种人,人数分别为p,a,c,m,另有1个权值g。
现在Eddy想在招募队伍各个职务的人数各不超过P,A,C,M的条件下使得g的和最大。
输出选择的队伍的编号(编号从0开始),如果有相同结果时任意输出。
思路: 01背包的多维质量,跟一维类似,多了个记录路径

#include<bits/stdc++.h>
using namespace std;
const int N=37;
int p[N],a[N],c[N],m[N],g[N];
bool path[N][N][N][N][N];
int dp[N][N][N][N];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d%d%d%d",&p[i],&a[i],&c[i],&m[i],&g[i]);
	}
	int pp,aa,cc,mm;
	scanf("%d%d%d%d",&pp,&aa,&cc,&mm);
	for(int i=0;i<n;i++)
	{
		for(int j=pp;j>=p[i];j--)
		{
			for(int k=aa;k>=a[i];k--)
			{
				for(int l=cc;l>=c[i];l--)
				{
					for(int r=mm;r>=m[i];r--)
					{
						if(dp[j][k][l][r]<dp[j-p[i]][k-a[i]][l-c[i]][r-m[i]]+g[i])
						{
							dp[j][k][l][r]=dp[j-p[i]][k-a[i]][l-c[i]][r-m[i]]+g[i];
							path[i][j][k][l][r]=true;
						}
					}
				}
			}
		}
	}
	vector<int>ans;
	for(int i=n-1;i>=0;i--)
	{
		if(path[i][pp][aa][cc][mm])
		{
			ans.push_back(i);
			pp-=p[i],aa-=a[i];
			cc-=c[i],mm-=m[i];
		}
	}
	printf("%d\n",ans.size());
	reverse(ans.begin(),ans.end());
	for(auto it: ans)
	{
		printf("%d ",it);
	}
	puts("");
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值