牛客多校3--第一题PACMteam

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

PACM Team
时间限制: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
输出
复制
0

动态规划—-01背包问题

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int N = 37;
int dp[N][N][N][N];
bool flag[N][N][N][N][N];
int p[N],a[N],c[N],m[N],g[N];
int P,A,C,M;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(dp,0,sizeof(dp));
        memset(flag,false,sizeof(flag));
        for(int i = 0;i < n;++i)
        {
            scanf("%d %d %d %d %d",&p[i],&a[i],&c[i],&m[i],&g[i]);
        }
        scanf("%d %d %d %d",&P,&A,&C,&M);
        for(int i = 0;i < n;++i)
        {
            for(int ia = P;ia >= p[i];--ia)
            {
                for(int ib = A;ib >= a[i];--ib)
                {
                    for(int ic = C;ic >= c[i];--ic)
                    {
                        for(int id = M;id >= m[i];--id)
                        {
                            if(dp[ia][ib][ic][id] < dp[ia - p[i]][ib - a[i]][ic - c[i]][id - m[i]] + g[i]){
                                flag[i][ia][ib][ic][id] = true;
                                dp[ia][ib][ic][id] = dp[ia - p[i]][ib - a[i]][ic - c[i]][id - m[i]] + g[i];
                            }
                        }
                    }
                }
            }
        }
        vector<int>ve;
        int x = P,y = A,z = C,j = M;
        for(int i = n - 1;i >= 0;--i)
        {
            if(flag[i][x][y][z][j]){
                ve.push_back(i);
                x -= p[i];
                y -= a[i];
                z -= c[i];
                j -= m[i];
            }
        }
        printf("%d\n",ve.size());
        reverse(ve.begin(),ve.end());
        for(vector<int>::iterator it = ve.begin();it != ve.end();++it)
        {
            printf("%d\n",*it);
        }
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值