牛客暑期训练赛 A题

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by coding(implementation ability), then math. However, in the ACM ICPC World Finals 2018, Eddy failed to solve a physics equation, which pushed him away from a potential medal.

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.

输入描述:

The first line contains a positive integer N indicating the number of candidate groups.
Each of following N lines contains five space-separated integer pi, ai, ci, mi, gi indicating that i-th team consists of pi physics experts, ai algorithm experts, ci coding experts, mi math experts, and will bring gi knowledge points.
The last line contains four space-separated integer P, A, C, M indicating the maximum possible number of physics experts, algorithm experts, coding experts, and math experts, respectively.

 1 ≤ N ≤ 36
 0 ≤ pi,ai,ci,mi,gi ≤ 36
 0 ≤ P, A, C, M ≤ 36

输出描述:

The first line should contain a non-negative integer K indicating the number of invited groups.
The second line should contain K space-separated integer indicating the index of invited groups(groups are indexed from 0).

You can output index in any order as long as each index appears at most once. If there are multiple way to reach the most total knowledge points, you can output any one of them. If none of the groups will be invited, you could either output one line or output a blank line in the second line.

示例1

输入

复制

2
1 0 2 1 10
1 0 2 1 21
1 0 2 1

输出

复制

1
1

示例2

输入

复制

1
2 1 1 0 31
1 0 2 1

输出

复制n

0

大致题意就是给出n支队伍,每个队伍有四个知识点数对应一个权重,然后最后一行输入四个知识点在最大点数,求在可能满足题目给出的四个点数的情况下,使权重最大

可以把最大点数看成背包容量,每个队伍的点数看成体积,权重即 价值 ,所以就是一个四维背包

#include <bits/stdc++.h>
using namespace std;
#define f(i,a,n) for (int i=a;i<n;i++)
short dp[37][37][37][37][37]={0};
short q[37],k=0;
short a[37],b[37],c[37],d[37],e[37];
int main()
{
	short n;
	cin>>n;
	f(i,0,n)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i]>>e[i];
	}
	short A,B,C,D;
	cin>>A>>B>>C>>D;
	
	f(i,0,n) f(j,0,A+1) f(x,0,B+1) f(y,0,C+1) f(z,0,D+1)
	{
		dp[i+1][j][x][y][z]=dp[i][j][x][y][z];
		if(j>=a[i]&&x>=b[i]&&y>=c[i]&&z>=d[i]&&dp[i][j][x][y][z]<dp[i][j-a[i]][x-b[i]][y-c[i]][z-d[i]]+e[i])
		{
			dp[i+1][j][x][y][z]=dp[i][j-a[i]][x-b[i]][y-c[i]][z-d[i]]+e[i];
		}
		
	}
	
	while(1)
	{
		if(n==0) break;
		if(dp[n-1][A][B][C][D]==dp[n][A][B][C][D])
		{
			n=n-1;
		}
		else{
			q[k++]=n-1;
			A-=a[n-1];
			B-=b[n-1];
			C-=c[n-1];
			D-=d[n-1];
            n=n-1;
		}
	}
	cout<<k<<endl;
    for(short i=k-1;i>=0;i--)
	{
		cout<<q[i];	
		if(i!=0)
		{
			cout<<" ";
		}
	}
	cout<<endl;
}

猜你喜欢

转载自blog.csdn.net/qq_38570571/article/details/81254879