牛客网暑期ACM多校训练营(第三场)A PACM Team

ACM团队组建策略
本文介绍了一种基于约束条件下的团队组建策略问题,通过动态规划算法确定最优组合以获得最高知识积分,同时确保各专业领域专家人数不超过限制。

链接:https://www.nowcoder.com/acm/contest/141/A
来源:牛客网
 

题目描述

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

 

这题其实没有什么记下来的意义但是路径记录还是第一次遇到所以还是mark一下

第一次交用的是价值的路径记录wa了 换成容量记录就好了(我也一脸懵逼)

这题卡内存所以mark还是用bool才行

#include <bits/stdc++.h>
using namespace std;
int dp[40][40][40][40];
bool mark[40][40][40][40][40];
int a[40],b[40],c[40],d[40],v[40];
int ans;
int xzh[100];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(dp,0,sizeof(dp));
        memset(mark,0,sizeof(mark));
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d%d",&a[i],&b[i],&c[i],&d[i],&v[i]);
        }
        int v1,v2,v3,v4;
        scanf("%d%d%d%d",&v1,&v2,&v3,&v4);
        for(int i=0;i<n;i++)
        {
            for(int k1=v1;k1>=a[i];k1--)
            {
                for(int k2=v2;k2>=b[i];k2--)
                {
                    for(int k3=v3;k3>=c[i];k3--)
                    {
                        for(int k4=v4;k4>=d[i];k4--)
                        {
                            if(dp[k1-a[i]][k2-b[i]][k3-c[i]][k4-d[i]]+v[i]>dp[k1][k2][k3][k4])
                            {
                                dp[k1][k2][k3][k4]=dp[k1-a[i]][k2-b[i]][k3-c[i]][k4-d[i]]+v[i];
                                mark[i][k1][k2][k3][k4]=1;
                            }
                        }
                    }
                }
            }
        }
        ans=0;
        for(int i=n-1;i>=0;i--)
        {
            if(mark[i][v1][v2][v3][v4])
            {
                v1-=a[i];
                v2-=b[i];
                v3-=c[i];
                v4-=d[i];
                xzh[ans]=i;
                ans++;
            }
        }
        printf("%d\n",ans);
        for(int i=ans-1;i>=0;i--)
        {
            if(i!=0) printf("%d ",xzh[i]);
            else printf("%d\n",xzh[i]);
        }
 
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值