牛客 多校(背包路径记录)

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

输出

0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const ll inf = 0x3f3f3f3f;

const int mx = 37;
int dp[mx][mx][mx][mx];
bool path[mx][mx][mx][mx][mx];
int ans[mx]; 
int n,P,A,C,M,G;
/*struct no{
	int p,a,c,m,g;
}po[mx];*/
int pp[mx],aa[mx],cc[mx],mm[mx],gg[mx];
int main(){
	//int T=10;	scanf("%d",&T);
	//	freopen("F:\\in.txt","r",stdin);
	s1(n);
	for(int i = 1; i <= n; i++){
		scanf("%d%d%d%d%d",pp+i,aa+i,cc+i,mm+i,gg+i);
	}
	scanf("%d%d%d%d",&P,&A,&C,&M);
	
	for(int i = 1; i <= n; i++){
		for(int p= P; p >= pp[i]; p--)
			for(int a =A; a>=aa[i]; a--)
				for(int c =C; c >= cc[i]; c--)
					for(int m =M; m>= mm[i]; m--){
							//cout<<"jin"<<endl; 
							if(dp[p][a][c][m] < dp[p-pp[i]][a-aa[i]][c-cc[i]][m-mm[i]] + gg[i]){
								dp[p][a][c][m] = dp[p-pp[i]][a-aa[i]][c-cc[i]][m-mm[i]] + gg[i];
								path[i][p][a][c][m] = 1;
							}
					} 
	}
	int co = 0,p=P,a=A,c=C,m=M;
	
	for(int i = n,p=P,a=A,c=C,m=M;i>0&&p>=0&&a>=0&&c>=0&&m>=0;i--){
		if(path[i][p][a][c][m]){
			ans[co++] = i;
			p -= pp[i];
			a -= aa[i];
			c -= cc[i];
			m -= mm[i];
		}
	
	}
	
	if(co){
		printf("%d\n",co);
		for(int i = 0; i < co; i++)
			printf("%d ",ans[i]-1);
		puts("");
	}
	else
		puts("0");
	
	
	//cout<<dp[n][P][A][C][M]<<endl;


	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Blaze Jack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值